Use Lua's random in util bindings

This commit is contained in:
DBotThePony 2024-05-22 18:58:30 +07:00
parent 96fdcccdd0
commit 1b7076f04f
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -94,15 +94,12 @@ private val staticRandomI32Range = luaFunctionN("staticRandomI32Range") {
returnBuffer.setTo(staticRandomLong(min, max, *it.copyRemaining()))
}
fun provideUtilityBindings(
lua: LuaEnvironment,
random: RandomGenerator = random()
) {
fun provideUtilityBindings(lua: LuaEnvironment) {
val table = lua.newTable()
lua.globals["sb"] = table
table["makeUuid"] = luaFunction {
returnBuffer.setTo(UUID(random.nextLong(), random.nextLong()).toStarboundString())
returnBuffer.setTo(UUID(lua.random.nextLong(), lua.random.nextLong()).toStarboundString())
}
table["logInfo"] = logInfo
@ -112,7 +109,7 @@ fun provideUtilityBindings(
table["nrand"] = luaFunctionN("nrand") { args ->
val stdev = args.nextOptionalFloat() ?: 1.0
val mean = args.nextOptionalFloat() ?: 0.0
random.nextNormalDouble(stdev, mean)
lua.random.nextNormalDouble(stdev, mean)
}
table["print"] = lua.globals["tostring"]
@ -120,7 +117,7 @@ fun provideUtilityBindings(
table["interpolateSinEase"] = interpolateSinEase
table["replaceTags"] = replaceTags
table["makeRandomSource"] = luaFunction { seed: Long? ->
returnBuffer.setTo(LuaRandomGenerator(random(seed ?: random.nextLong())))
returnBuffer.setTo(LuaRandomGenerator(random(seed ?: lua.random.nextLong())))
}
table["makePerlinSource"] = makePerlinSource