Use Lua's random in util bindings
This commit is contained in:
parent
96fdcccdd0
commit
1b7076f04f
@ -94,15 +94,12 @@ private val staticRandomI32Range = luaFunctionN("staticRandomI32Range") {
|
|||||||
returnBuffer.setTo(staticRandomLong(min, max, *it.copyRemaining()))
|
returnBuffer.setTo(staticRandomLong(min, max, *it.copyRemaining()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun provideUtilityBindings(
|
fun provideUtilityBindings(lua: LuaEnvironment) {
|
||||||
lua: LuaEnvironment,
|
|
||||||
random: RandomGenerator = random()
|
|
||||||
) {
|
|
||||||
val table = lua.newTable()
|
val table = lua.newTable()
|
||||||
lua.globals["sb"] = table
|
lua.globals["sb"] = table
|
||||||
|
|
||||||
table["makeUuid"] = luaFunction {
|
table["makeUuid"] = luaFunction {
|
||||||
returnBuffer.setTo(UUID(random.nextLong(), random.nextLong()).toStarboundString())
|
returnBuffer.setTo(UUID(lua.random.nextLong(), lua.random.nextLong()).toStarboundString())
|
||||||
}
|
}
|
||||||
|
|
||||||
table["logInfo"] = logInfo
|
table["logInfo"] = logInfo
|
||||||
@ -112,7 +109,7 @@ fun provideUtilityBindings(
|
|||||||
table["nrand"] = luaFunctionN("nrand") { args ->
|
table["nrand"] = luaFunctionN("nrand") { args ->
|
||||||
val stdev = args.nextOptionalFloat() ?: 1.0
|
val stdev = args.nextOptionalFloat() ?: 1.0
|
||||||
val mean = args.nextOptionalFloat() ?: 0.0
|
val mean = args.nextOptionalFloat() ?: 0.0
|
||||||
random.nextNormalDouble(stdev, mean)
|
lua.random.nextNormalDouble(stdev, mean)
|
||||||
}
|
}
|
||||||
|
|
||||||
table["print"] = lua.globals["tostring"]
|
table["print"] = lua.globals["tostring"]
|
||||||
@ -120,7 +117,7 @@ fun provideUtilityBindings(
|
|||||||
table["interpolateSinEase"] = interpolateSinEase
|
table["interpolateSinEase"] = interpolateSinEase
|
||||||
table["replaceTags"] = replaceTags
|
table["replaceTags"] = replaceTags
|
||||||
table["makeRandomSource"] = luaFunction { seed: Long? ->
|
table["makeRandomSource"] = luaFunction { seed: Long? ->
|
||||||
returnBuffer.setTo(LuaRandomGenerator(random(seed ?: random.nextLong())))
|
returnBuffer.setTo(LuaRandomGenerator(random(seed ?: lua.random.nextLong())))
|
||||||
}
|
}
|
||||||
|
|
||||||
table["makePerlinSource"] = makePerlinSource
|
table["makePerlinSource"] = makePerlinSource
|
||||||
|
Loading…
Reference in New Issue
Block a user