28 #define ERR_LUA LOG_STREAM(err, log_lua)
35 static const char *
Rng =
"Rng";
39 uint32_t seed = lua_kernel_base::get_lua_kernel<lua_kernel_base>(L).get_random_seed();
41 luaL_setmetatable(L,
Rng);
50 ERR_LUA <<
"rng_destroy called on data of type: " << lua_typename( L, lua_type( L, 1 ) );
51 ERR_LUA <<
"This may indicate a memory leak, please report at bugs.wesnoth.org";
52 lua_pushstring(L,
"Rng object garbage collection failure");
63 std::string seed = luaL_checkstring(L, 2);
81 luaL_newmetatable(L,
Rng);
83 static luaL_Reg
const callbacks[] {
90 luaL_setfuncs(L, callbacks, 0);
93 lua_setfield(L, -2,
"__index");
95 lua_setglobal(L,
Rng);
uint32_t get_next_random()
Get a new random number.
void seed_random(const std::string &seed, const unsigned int call_count=0)
Same as uint32_t version, but uses a stringstream to convert given hex string.
Standard logging facilities (interface).
static lg::log_domain log_lua("scripting/lua")
int impl_rng_create(lua_State *L)
Implementations for lua callbacks.
int impl_rng_draw(lua_State *L)
int impl_rng_seed(lua_State *L)
int impl_rng_destroy(lua_State *L)
void load_tables(lua_State *L)
Creates the metatable for RNG objects, and adds the Rng table which contains the constructor.