aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_util.cpp
Commit message (Expand)AuthorAge
* Use a settings object for the main settingsShadowNinja2017-05-06
* [CSM] storage + fixesLoic Blot2017-03-13
* [CSM] sound_play & sound_stop support + client_lua_api doc (#5096)Loïc Blot2017-03-13
* [CSM] Add method that display chat to client-sided lua. (#5089) (#5091)red-0012017-03-13
* Dont compare short with bool (#4963)adrido2016-12-28
* Mod security: Allow read-only access to all mod pathsShadowNinja2016-12-20
* Add version APIShadowNinja2016-10-31
* Replace various std::map with UNORDERED_MAP + various cleanupsLoic Blot2016-10-05
* Fixes for compiling with a newer (system) jsoncpp (#4429)Rogier-52016-08-10
* Fix l_request_insecure_environment not ignoring all whitespace (#4395)Dorian Wouters2016-08-04
* Add minetest.check_password_entry callbackest312016-05-30
* Add base64 encoding and decoding to the lua api. (#3919)red-0012016-05-27
* Much better API for auth.{cpp, h}est312016-03-15
* Move AreaStore to utilShadowNinja2016-03-07
* Use LuaErrors in security check macrosShadowNinja2016-03-07
* Fix main menu being unable to set secure settingsShadowNinja2016-03-03
* Fix minetest.request_insecure_environment() always returning nilJeija2016-02-26
* Ignore spaces in secure.trusted_mods settingJeija2016-02-19
* Require request_insecure_environment to be called from the mod's main scopeShadowNinja2016-02-19
* Don't print whole json data buffer to errorstream on errorest312016-01-28
* SAPI: Move core.get_us_time() to Util modulekwolekr2015-10-26
* SAPI: Mark all Lua API functions requiring envlockkwolekr2015-10-25
* Correct comment in l_util.cppest312015-10-26
* Refactor loggingShadowNinja2015-10-14
* Use numeric indices and raw table access with LUA_REGISTRYINDEXKahrl2015-08-27
* Add AreaStore data structureest312015-07-27
* Add core.get_dir_listShadowNinja2015-05-16
* Add core.request_insecure_environment()ShadowNinja2015-05-16
* Add core.mkdirShadowNinja2015-05-16
* Add mod securityShadowNinja2015-05-16
* Make early protocol auth mechanism generic, and add SRPest312015-05-11
* Refactor around translatePasswordest312015-04-17
* Move globals from main.cpp to more sane locationsCraig Robbins2015-04-01
* Split settings into seperate source and header filesShadowNinja2014-09-21
* Add compression APIShadowNinja2014-09-20
* Make print() NUL-safeShadowNinja2014-05-15
* Organize builtin into subdirectoriesShadowNinja2014-05-07
* Add write_json() to the async APIShadowNinja2014-05-07
* Add proper lua api deprecated handlingsapier2014-04-29
* Remove dependency on marshal and many other async changesShadowNinja2014-04-27
* Rename get_json_value to read_json_valueShadowNinja2014-01-11
* Don't throw a error when writing JSON failsShadowNinja2013-12-18
* Add 'minetest.write_json'ShadowNinja2013-12-18
* Fix modstore/favourites hang by adding asynchronous lua job supportsapier2013-11-29
* Allow non-string arguments for minetest.is_yes()PilzAdam2013-09-10
* Add Settings interface for LuaPilzAdam2013-09-10
* Add minetest.parse_json, engine.parse_jsonKahrl2013-09-02
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
">::string(luaL_checkstring(L, 2)); const char* value = luaL_checkstring(L, 3); if (!o->m_settings->set(key, value)) throw LuaError("Invalid sequence found in setting parameters"); return 0; } // remove(self, key) -> success int LuaSettings::l_remove(lua_State* L) { NO_MAP_LOCK_REQUIRED; LuaSettings* o = checkobject(L, 1); std::string key = std::string(luaL_checkstring(L, 2)); bool success = o->m_settings->remove(key); lua_pushboolean(L, success); return 1; } // get_names(self) -> {key1, ...} int LuaSettings::l_get_names(lua_State* L) { NO_MAP_LOCK_REQUIRED; LuaSettings* o = checkobject(L, 1); std::vector<std::string> keys = o->m_settings->getNames(); lua_newtable(L); for (unsigned int i=0; i < keys.size(); i++) { lua_pushstring(L, keys[i].c_str()); lua_rawseti(L, -2, i + 1); } return 1; } // write(self) -> success int LuaSettings::l_write(lua_State* L) { NO_MAP_LOCK_REQUIRED; LuaSettings* o = checkobject(L, 1); bool success = o->m_settings->updateConfigFile(o->m_filename.c_str()); lua_pushboolean(L, success); return 1; } // to_table(self) -> {[key1]=value1,...} int LuaSettings::l_to_table(lua_State* L) { NO_MAP_LOCK_REQUIRED; LuaSettings* o = checkobject(L, 1); std::vector<std::string> keys = o->m_settings->getNames(); lua_newtable(L); for (unsigned int i=0; i < keys.size(); i++) { lua_pushstring(L, o->m_settings->get(keys[i]).c_str()); lua_setfield(L, -2, keys[i].c_str()); } return 1; } LuaSettings::LuaSettings(const char* filename) { m_filename = std::string(filename); m_settings = new Settings(); m_settings->readConfigFile(m_filename.c_str()); } LuaSettings::~LuaSettings() { delete m_settings; } void LuaSettings::Register(lua_State* L) { lua_newtable(L); int methodtable = lua_gettop(L); luaL_newmetatable(L, className); int metatable = lua_gettop(L); lua_pushliteral(L, "__metatable"); lua_pushvalue(L, methodtable); lua_settable(L, metatable); // hide metatable from Lua getmetatable() lua_pushliteral(L, "__index"); lua_pushvalue(L, methodtable); lua_settable(L, metatable); lua_pushliteral(L, "__gc"); lua_pushcfunction(L, gc_object); lua_settable(L, metatable); lua_pop(L, 1); // drop metatable luaL_openlib(L, 0, methods, 0); // fill methodtable lua_pop(L, 1); // drop methodtable // Can be created from Lua (Settings(filename)) lua_register(L, className, create_object); } // LuaSettings(filename) // Creates an LuaSettings and leaves it on top of stack int LuaSettings::create_object(lua_State* L) { NO_MAP_LOCK_REQUIRED; const char* filename = luaL_checkstring(L, 1); LuaSettings* o = new LuaSettings(filename); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; luaL_getmetatable(L, className); lua_setmetatable(L, -2); return 1; } LuaSettings* LuaSettings::checkobject(lua_State* L, int narg) { NO_MAP_LOCK_REQUIRED; luaL_checktype(L, narg, LUA_TUSERDATA); void *ud = luaL_checkudata(L, narg, className); if(!ud) luaL_typerror(L, narg, className); return *(LuaSettings**)ud; // unbox pointer } const char LuaSettings::className[] = "Settings"; const luaL_reg LuaSettings::methods[] = { luamethod(LuaSettings, get), luamethod(LuaSettings, get_bool), luamethod(LuaSettings, set), luamethod(LuaSettings, remove), luamethod(LuaSettings, get_names), luamethod(LuaSettings, write), luamethod(LuaSettings, to_table), {0,0} };