Lua setting getter
parent
f93144fee7
commit
234bf99743
|
@ -18,6 +18,8 @@
|
||||||
-- minetest.register_on_newplayer(func(ObjectRef))
|
-- minetest.register_on_newplayer(func(ObjectRef))
|
||||||
-- minetest.register_on_respawnplayer(func(ObjectRef))
|
-- minetest.register_on_respawnplayer(func(ObjectRef))
|
||||||
-- ^ return true in func to disable regular player placement
|
-- ^ return true in func to disable regular player placement
|
||||||
|
-- minetest.setting_get(name)
|
||||||
|
-- minetest.setting_getbool(name)
|
||||||
--
|
--
|
||||||
-- Global objects:
|
-- Global objects:
|
||||||
-- minetest.env - environment reference
|
-- minetest.env - environment reference
|
||||||
|
@ -1313,6 +1315,9 @@ minetest.register_on_respawnplayer(function(player)
|
||||||
-- return true
|
-- return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Example setting get
|
||||||
|
print("max_users = " .. dump(minetest.setting_get("max_users")))
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Done, print some random stuff
|
-- Done, print some random stuff
|
||||||
--
|
--
|
||||||
|
|
|
@ -38,6 +38,8 @@ extern "C" {
|
||||||
#include "tooldef.h"
|
#include "tooldef.h"
|
||||||
#include "nodedef.h"
|
#include "nodedef.h"
|
||||||
#include "craftdef.h"
|
#include "craftdef.h"
|
||||||
|
#include "main.h" // For g_settings
|
||||||
|
#include "settings.h" // For accessing g_settings
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
|
@ -855,6 +857,24 @@ static int l_register_on_respawnplayer(lua_State *L)
|
||||||
return register_lua_callback(L, "registered_on_respawnplayers");
|
return register_lua_callback(L, "registered_on_respawnplayers");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setting_get(name)
|
||||||
|
static int l_setting_get(lua_State *L)
|
||||||
|
{
|
||||||
|
const char *name = luaL_checkstring(L, 1);
|
||||||
|
std::string value = g_settings->get(name);
|
||||||
|
lua_pushstring(L, value.c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// setting_getbool(name)
|
||||||
|
static int l_setting_getbool(lua_State *L)
|
||||||
|
{
|
||||||
|
const char *name = luaL_checkstring(L, 1);
|
||||||
|
bool value = g_settings->getBool(name);
|
||||||
|
lua_pushboolean(L, value);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct luaL_Reg minetest_f [] = {
|
static const struct luaL_Reg minetest_f [] = {
|
||||||
{"register_nodedef_defaults", l_register_nodedef_defaults},
|
{"register_nodedef_defaults", l_register_nodedef_defaults},
|
||||||
{"register_entity", l_register_entity},
|
{"register_entity", l_register_entity},
|
||||||
|
@ -867,6 +887,8 @@ static const struct luaL_Reg minetest_f [] = {
|
||||||
{"register_on_punchnode", l_register_on_punchnode},
|
{"register_on_punchnode", l_register_on_punchnode},
|
||||||
{"register_on_newplayer", l_register_on_newplayer},
|
{"register_on_newplayer", l_register_on_newplayer},
|
||||||
{"register_on_respawnplayer", l_register_on_respawnplayer},
|
{"register_on_respawnplayer", l_register_on_respawnplayer},
|
||||||
|
{"setting_get", l_setting_get},
|
||||||
|
{"setting_getbool", l_setting_getbool},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue