Fix mapgen Lua kernel using the wrong random function

This simply overwrites mathx.random in the mapgen kernel.

Fixes #5846
This commit is contained in:
Celtic Minstrel 2021-06-11 21:57:55 -04:00
parent 2190792369
commit 1313a8ddd3

View file

@ -49,7 +49,7 @@ int dispatch(lua_State *L) {
}
/**
* Returns a random numer, same interface as math.random.
* Returns a random number, same interface as math.random.
*/
static int intf_random(lua_State *L)
{
@ -211,10 +211,10 @@ mapgen_lua_kernel::mapgen_lua_kernel(const config* vars)
{
lua_State *L = mState;
// Unset wesnoth.random. This guarantees that the mapgen_lua_kernel version
// of wesnoth.random overrides the lua_kernel_base version.
lua_getglobal(L, "wesnoth");
lua_pushnil(L);
// Overwrite mathx.random. This guarantees that the mapgen_lua_kernel version
// of mathx.random overrides the lua_kernel_base version.
lua_getglobal(L, "mathx");
lua_pushcfunction(L, &intf_random);
lua_setfield(L, -2, "random");
lua_settop(L, 0);