provideConfigBindings
This commit is contained in:
parent
242f372819
commit
56c154cc96
@ -1,11 +1,14 @@
|
||||
package ru.dbotthepony.kstarbound.lua.bindings
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import org.classdump.luna.ByteString
|
||||
import org.classdump.luna.Table
|
||||
import org.classdump.luna.runtime.ExecutionContext
|
||||
import ru.dbotthepony.kstarbound.math.vector.Vector2d
|
||||
import ru.dbotthepony.kstarbound.Starbound
|
||||
import ru.dbotthepony.kstarbound.defs.PerlinNoiseParameters
|
||||
import ru.dbotthepony.kstarbound.json.JsonPath
|
||||
import ru.dbotthepony.kstarbound.lua.LuaEnvironment
|
||||
import ru.dbotthepony.kstarbound.lua.from
|
||||
import ru.dbotthepony.kstarbound.lua.get
|
||||
@ -130,3 +133,18 @@ fun provideUtilityBindings(lua: LuaEnvironment) {
|
||||
table["staticRandomI32Range"] = staticRandomI32Range
|
||||
table["staticRandomI64Range"] = staticRandomI32Range
|
||||
}
|
||||
|
||||
fun provideConfigBindings(lua: LuaEnvironment, lookup: ExecutionContext.(path: JsonPath, ifMissing: Any?) -> Any?) {
|
||||
val config = lua.newTable()
|
||||
lua.globals["config"] = config
|
||||
config["getParameter"] = createConfigBinding(lookup)
|
||||
}
|
||||
|
||||
fun createConfigBinding(lookup: ExecutionContext.(path: JsonPath, ifMissing: Any?) -> Any?) = luaFunction { name: ByteString, default: Any? ->
|
||||
val get = lookup(this, JsonPath.query(name.decode()), default)
|
||||
|
||||
if (get is JsonElement)
|
||||
returnBuffer.setTo(from(get))
|
||||
else
|
||||
returnBuffer.setTo(get)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user