From c4359ff65cd8e4e754442b9f2ef7051a8eaa4241 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sun, 27 Apr 2014 21:02:48 -0400 Subject: [PATCH] Use "core" namespace internally --- builtin/async/init.lua | 3 +- builtin/common/async_event.lua | 10 +- builtin/common/misc_helpers.lua | 64 +++-- builtin/common/serialize.lua | 10 +- builtin/game/auth.lua | 106 ++++---- builtin/game/chatcommands.lua | 388 ++++++++++++++-------------- builtin/game/deprecated.lua | 38 +-- builtin/game/detached_inventory.lua | 8 +- builtin/game/falling.lua | 82 +++--- builtin/game/features.lua | 8 +- builtin/game/forceloading.lua | 30 +-- builtin/game/item.lua | 160 ++++++------ builtin/game/item_entity.lua | 20 +- builtin/game/misc.lua | 70 ++--- builtin/game/privileges.lua | 38 +-- builtin/game/register.lua | 180 ++++++------- builtin/game/statbars.lua | 12 +- builtin/game/static_spawn.lua | 18 +- builtin/init.lua | 4 +- builtin/mainmenu/init.lua | 7 +- builtin/mainmenu/modmgr.lua | 14 +- doc/menu_lua_api.txt | 8 +- src/script/common/c_content.cpp | 8 +- src/script/common/c_internal.cpp | 4 +- src/script/cpp_api/s_async.cpp | 19 +- src/script/cpp_api/s_base.cpp | 28 +- src/script/cpp_api/s_entity.cpp | 26 +- src/script/cpp_api/s_env.cpp | 16 +- src/script/cpp_api/s_inventory.cpp | 4 +- src/script/cpp_api/s_item.cpp | 16 +- src/script/cpp_api/s_mainmenu.cpp | 8 +- src/script/cpp_api/s_player.cpp | 32 +-- src/script/cpp_api/s_server.cpp | 10 +- src/script/lua_api/l_env.cpp | 86 +++--- src/script/lua_api/l_env.h | 68 ++--- src/script/lua_api/l_inventory.cpp | 2 +- src/script/lua_api/l_inventory.h | 2 +- src/script/lua_api/l_item.cpp | 6 +- src/script/lua_api/l_item.h | 2 +- src/script/lua_api/l_mapgen.cpp | 6 +- src/script/lua_api/l_mapgen.h | 6 +- src/script/lua_api/l_server.cpp | 2 +- src/script/lua_api/l_util.h | 5 +- src/script/scripting_game.cpp | 11 +- src/script/scripting_mainmenu.cpp | 10 +- 45 files changed, 812 insertions(+), 843 deletions(-) diff --git a/builtin/async/init.lua b/builtin/async/init.lua index 79b1a0a6c..1b2549685 100644 --- a/builtin/async/init.lua +++ b/builtin/async/init.lua @@ -1,6 +1,5 @@ -engine.log("info", "Initializing Asynchronous environment") -local core = engine or minetest +core.log("info", "Initializing Asynchronous environment") function core.job_processor(serialized_func, serialized_param) local func = loadstring(serialized_func) diff --git a/builtin/common/async_event.lua b/builtin/common/async_event.lua index ef4bf4354..988af79b9 100644 --- a/builtin/common/async_event.lua +++ b/builtin/common/async_event.lua @@ -1,6 +1,4 @@ -local core = engine or minetest - core.async_jobs = {} local function handle_job(jobid, serialized_retval) @@ -10,14 +8,14 @@ local function handle_job(jobid, serialized_retval) core.async_jobs[jobid] = nil end -if engine ~= nil then - core.async_event_handler = handle_job -else - minetest.register_globalstep(function(dtime) +if core.register_globalstep then + core.register_globalstep(function(dtime) for i, job in ipairs(core.get_finished_jobs()) do handle_job(job.jobid, job.retval) end end) +else + core.async_event_handler = handle_job end function core.handle_async(func, parameter, callback) diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 9c7349726..38a7b1879 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -173,8 +173,7 @@ function cleanup_path(temppath) return temppath end -local tbl = engine or minetest -function tbl.formspec_escape(text) +function core.formspec_escape(text) if text ~= nil then text = string.gsub(text,"\\","\\\\") text = string.gsub(text,"%]","\\]") @@ -186,7 +185,7 @@ function tbl.formspec_escape(text) end -function tbl.splittext(text,charlimit) +function core.splittext(text,charlimit) local retval = {} local current_idx = 1 @@ -243,33 +242,33 @@ end -------------------------------------------------------------------------------- -if minetest then +if INIT == "game" then local dirs1 = {9, 18, 7, 12} local dirs2 = {20, 23, 22, 21} - function minetest.rotate_and_place(itemstack, placer, pointed_thing, + function core.rotate_and_place(itemstack, placer, pointed_thing, infinitestacks, orient_flags) orient_flags = orient_flags or {} - local unode = minetest.get_node_or_nil(pointed_thing.under) + local unode = core.get_node_or_nil(pointed_thing.under) if not unode then return end - local undef = minetest.registered_nodes[unode.name] + local undef = core.registered_nodes[unode.name] if undef and undef.on_rightclick then undef.on_rightclick(pointed_thing.under, unode, placer, itemstack, pointed_thing) return end local pitch = placer:get_look_pitch() - local fdir = minetest.dir_to_facedir(placer:get_look_dir()) + local fdir = core.dir_to_facedir(placer:get_look_dir()) local wield_name = itemstack:get_name() local above = pointed_thing.above local under = pointed_thing.under local iswall = (above.y == under.y) local isceiling = not iswall and (above.y < under.y) - local anode = minetest.get_node_or_nil(above) + local anode = core.get_node_or_nil(above) if not anode then return end @@ -282,13 +281,13 @@ if minetest then iswall = false end - if minetest.is_protected(pos, placer:get_player_name()) then - minetest.record_protection_violation(pos, + if core.is_protected(pos, placer:get_player_name()) then + core.record_protection_violation(pos, placer:get_player_name()) return end - local ndef = minetest.registered_nodes[node.name] + local ndef = core.registered_nodes[node.name] if not ndef or not ndef.buildable_to then return end @@ -307,22 +306,22 @@ if minetest then end if iswall then - minetest.set_node(pos, {name = wield_name, + core.set_node(pos, {name = wield_name, param2 = dirs1[fdir+1]}) elseif isceiling then if orient_flags.force_facedir then - minetest.set_node(pos, {name = wield_name, + core.set_node(pos, {name = wield_name, param2 = 20}) else - minetest.set_node(pos, {name = wield_name, + core.set_node(pos, {name = wield_name, param2 = dirs2[fdir+1]}) end else -- place right side up if orient_flags.force_facedir then - minetest.set_node(pos, {name = wield_name, + core.set_node(pos, {name = wield_name, param2 = 0}) else - minetest.set_node(pos, {name = wield_name, + core.set_node(pos, {name = wield_name, param2 = fdir}) end end @@ -340,16 +339,16 @@ if minetest then -------------------------------------------------------------------------------- - minetest.rotate_node = function(itemstack, placer, pointed_thing) - minetest.rotate_and_place(itemstack, placer, pointed_thing, - minetest.setting_getbool("creative_mode"), + core.rotate_node = function(itemstack, placer, pointed_thing) + core.rotate_and_place(itemstack, placer, pointed_thing, + core.setting_getbool("creative_mode"), {invert_wall = placer:get_player_control().sneak}) return itemstack end end -------------------------------------------------------------------------------- -function tbl.explode_table_event(evt) +function core.explode_table_event(evt) if evt ~= nil then local parts = evt:split(":") if #parts == 3 then @@ -365,7 +364,7 @@ function tbl.explode_table_event(evt) end -------------------------------------------------------------------------------- -function tbl.explode_textlist_event(evt) +function core.explode_textlist_event(evt) if evt ~= nil then local parts = evt:split(":") if #parts == 2 then @@ -379,11 +378,15 @@ function tbl.explode_textlist_event(evt) return {type="INV", index=0} end +function core.pos_to_string(pos) + return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")" +end + -------------------------------------------------------------------------------- -- mainmenu only functions -------------------------------------------------------------------------------- -if engine ~= nil then - engine.get_game = function(index) +if INIT == "mainmenu" then + function core.get_game(index) local games = game.get_games() if index > 0 and index <= #games then @@ -394,7 +397,7 @@ if engine ~= nil then end function fgettext(text, ...) - text = engine.gettext(text) + text = core.gettext(text) local arg = {n=select('#', ...), ...} if arg.n >= 1 then -- Insert positional parameters ($1, $2, ...) @@ -413,16 +416,7 @@ if engine ~= nil then end text = result end - return engine.formspec_escape(text) - end -end --------------------------------------------------------------------------------- --- core only fct --------------------------------------------------------------------------------- -if minetest ~= nil then - -------------------------------------------------------------------------------- - function minetest.pos_to_string(pos) - return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")" + return core.formspec_escape(text) end end diff --git a/builtin/common/serialize.lua b/builtin/common/serialize.lua index 93fffe80d..6cb94709c 100644 --- a/builtin/common/serialize.lua +++ b/builtin/common/serialize.lua @@ -14,7 +14,7 @@ local no_identity = { number=1, boolean=1, string=1, ['nil']=1 } -function minetest.serialize(x) +function core.serialize(x) local gensym_max = 0 -- index of the gensym() symbol generator local seen_once = { } -- element->true set of elements seen exactly once in the table @@ -188,13 +188,13 @@ local function stringtotable(sdata, safe) return f() end -function minetest.deserialize(sdata, safe) +function core.deserialize(sdata, safe) local table = {} local okay, results = pcall(stringtotable, sdata, safe) if okay then return results end - minetest.log('error', 'minetest.deserialize(): '.. results) + core.log('error', 'core.deserialize(): '.. results) return nil end @@ -207,14 +207,14 @@ local function unit_test() end unittest_input = {cat={sound="nyan", speed=400}, dog={sound="woof"}} - unittest_output = minetest.deserialize(minetest.serialize(unittest_input)) + unittest_output = core.deserialize(core.serialize(unittest_input)) unitTest("test 1a", unittest_input.cat.sound == unittest_output.cat.sound) unitTest("test 1b", unittest_input.cat.speed == unittest_output.cat.speed) unitTest("test 1c", unittest_input.dog.sound == unittest_output.dog.sound) unittest_input = {escapechars="\n\r\t\v\\\"\'", noneuropean="θשׁ٩∂"} - unittest_output = minetest.deserialize(minetest.serialize(unittest_input)) + unittest_output = core.deserialize(core.serialize(unittest_input)) unitTest("test 3a", unittest_input.escapechars == unittest_output.escapechars) unitTest("test 3b", unittest_input.noneuropean == unittest_output.noneuropean) end diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua index b6cca609c..5c62dbf28 100644 --- a/builtin/game/auth.lua +++ b/builtin/game/auth.lua @@ -4,7 +4,7 @@ -- Authentication handler -- -function minetest.string_to_privs(str, delim) +function core.string_to_privs(str, delim) assert(type(str) == "string") delim = delim or ',' privs = {} @@ -14,7 +14,7 @@ function minetest.string_to_privs(str, delim) return privs end -function minetest.privs_to_string(privs, delim) +function core.privs_to_string(privs, delim) assert(type(privs) == "table") delim = delim or ',' list = {} @@ -26,17 +26,17 @@ function minetest.privs_to_string(privs, delim) return table.concat(list, delim) end -assert(minetest.string_to_privs("a,b").b == true) -assert(minetest.privs_to_string({a=true,b=true}) == "a,b") +assert(core.string_to_privs("a,b").b == true) +assert(core.privs_to_string({a=true,b=true}) == "a,b") -minetest.auth_file_path = minetest.get_worldpath().."/auth.txt" -minetest.auth_table = {} +core.auth_file_path = core.get_worldpath().."/auth.txt" +core.auth_table = {} local function read_auth_file() local newtable = {} - local file, errmsg = io.open(minetest.auth_file_path, 'rb') + local file, errmsg = io.open(core.auth_file_path, 'rb') if not file then - minetest.log("info", minetest.auth_file_path.." could not be opened for reading ("..errmsg.."); assuming new world") + core.log("info", core.auth_file_path.." could not be opened for reading ("..errmsg.."); assuming new world") return end for line in file:lines() do @@ -45,31 +45,31 @@ local function read_auth_file() if not name or not password or not privilegestring then error("Invalid line in auth.txt: "..dump(line)) end - local privileges = minetest.string_to_privs(privilegestring) + local privileges = core.string_to_privs(privilegestring) newtable[name] = {password=password, privileges=privileges} end end io.close(file) - minetest.auth_table = newtable - minetest.notify_authentication_modified() + core.auth_table = newtable + core.notify_authentication_modified() end local function save_auth_file() local newtable = {} -- Check table for validness before attempting to save - for name, stuff in pairs(minetest.auth_table) do + for name, stuff in pairs(core.auth_table) do assert(type(name) == "string") assert(name ~= "") assert(type(stuff) == "table") assert(type(stuff.password) == "string") assert(type(stuff.privileges) == "table") end - local file, errmsg = io.open(minetest.auth_file_path, 'w+b') + local file, errmsg = io.open(core.auth_file_path, 'w+b') if not file then - error(minetest.auth_file_path.." could not be opened for writing: "..errmsg) + error(core.auth_file_path.." could not be opened for writing: "..errmsg) end - for name, stuff in pairs(minetest.auth_table) do - local privstring = minetest.privs_to_string(stuff.privileges) + for name, stuff in pairs(core.auth_table) do + local privstring = core.privs_to_string(stuff.privileges) file:write(name..":"..stuff.password..":"..privstring..'\n') end io.close(file) @@ -77,7 +77,7 @@ end read_auth_file() -minetest.builtin_auth_handler = { +core.builtin_auth_handler = { get_auth = function(name) assert(type(name) == "string") -- Figure out what password to use for a new player (singleplayer @@ -85,52 +85,52 @@ minetest.builtin_auth_handler = { -- usually empty too) local new_password_hash = "" -- If not in authentication table, return nil - if not minetest.auth_table[name] then + if not core.auth_table[name] then return nil end -- Figure out what privileges the player should have. -- Take a copy of the privilege table local privileges = {} - for priv, _ in pairs(minetest.auth_table[name].privileges) do + for priv, _ in pairs(core.auth_table[name].privileges) do privileges[priv] = true end -- If singleplayer, give all privileges except those marked as give_to_singleplayer = false - if minetest.is_singleplayer() then - for priv, def in pairs(minetest.registered_privileges) do + if core.is_singleplayer() then + for priv, def in pairs(core.registered_privileges) do if def.give_to_singleplayer then privileges[priv] = true end end -- For the admin, give everything - elseif name == minetest.setting_get("name") then - for priv, def in pairs(minetest.registered_privileges) do + elseif name == core.setting_get("name") then + for priv, def in pairs(core.registered_privileges) do privileges[priv] = true end end -- All done return { - password = minetest.auth_table[name].password, + password = core.auth_table[name].password, privileges = privileges, } end, create_auth = function(name, password) assert(type(name) == "string") assert(type(password) == "string") - minetest.log('info', "Built-in authentication handler adding player '"..name.."'") - minetest.auth_table[name] = { + core.log('info', "Built-in authentication handler adding player '"..name.."'") + core.auth_table[name] = { password = password, - privileges = minetest.string_to_privs(minetest.setting_get("default_privs")), + privileges = core.string_to_privs(core.setting_get("default_privs")), } save_auth_file() end, set_password = function(name, password) assert(type(name) == "string") assert(type(password) == "string") - if not minetest.auth_table[name] then - minetest.builtin_auth_handler.create_auth(name, password) + if not core.auth_table[name] then + core.builtin_auth_handler.create_auth(name, password) else - minetest.log('info', "Built-in authentication handler setting password of player '"..name.."'") - minetest.auth_table[name].password = password + core.log('info', "Built-in authentication handler setting password of player '"..name.."'") + core.auth_table[name].password = password save_auth_file() end return true @@ -138,11 +138,11 @@ minetest.builtin_auth_handler = { set_privileges = function(name, privileges) assert(type(name) == "string") assert(type(privileges) == "table") - if not minetest.auth_table[name] then - minetest.builtin_auth_handler.create_auth(name, minetest.get_password_hash(name, minetest.setting_get("default_password"))) + if not core.auth_table[name] then + core.builtin_auth_handler.create_auth(name, core.get_password_hash(name, core.setting_get("default_password"))) end - minetest.auth_table[name].privileges = privileges - minetest.notify_authentication_modified(name) + core.auth_table[name].privileges = privileges + core.notify_authentication_modified(name) save_auth_file() end, reload = function() @@ -151,36 +151,36 @@ minetest.builtin_auth_handler = { end, } -function minetest.register_authentication_handler(handler) - if minetest.registered_auth_handler then - error("Add-on authentication handler already registered by "..minetest.registered_auth_handler_modname) +function core.register_authentication_handler(handler) + if core.registered_auth_handler then + error("Add-on authentication handler already registered by "..core.registered_auth_handler_modname) end - minetest.registered_auth_handler = handler - minetest.registered_auth_handler_modname = minetest.get_current_modname() + core.registered_auth_handler = handler + core.registered_auth_handler_modname = core.get_current_modname() end -function minetest.get_auth_handler() - if minetest.registered_auth_handler then - return minetest.registered_auth_handler +function core.get_auth_handler() + if core.registered_auth_handler then + return core.registered_auth_handler end - return minetest.builtin_auth_handler + return core.builtin_auth_handler end -function minetest.set_player_password(name, password) - if minetest.get_auth_handler().set_password then - minetest.get_auth_handler().set_password(name, password) +function core.set_player_password(name, password) + if core.get_auth_handler().set_password then + core.get_auth_handler().set_password(name, password) end end -function minetest.set_player_privs(name, privs) - if minetest.get_auth_handler().set_privileges then - minetest.get_auth_handler().set_privileges(name, privs) +function core.set_player_privs(name, privs) + if core.get_auth_handler().set_privileges then + core.get_auth_handler().set_privileges(name, privs) end end -function minetest.auth_reload() - if minetest.get_auth_handler().reload then - return minetest.get_auth_handler().reload() +function core.auth_reload() + if core.get_auth_handler().reload then + return core.get_auth_handler().reload() end return false end diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index f8df83d8e..6c5fea693 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -4,27 +4,27 @@ -- Chat command handler -- -minetest.chatcommands = {} -function minetest.register_chatcommand(cmd, def) +core.chatcommands = {} +function core.register_chatcommand(cmd, def) def = def or {} def.params = def.params or "" def.description = def.description or "" def.privs = def.privs or {} - minetest.chatcommands[cmd] = def + core.chatcommands[cmd] = def end -minetest.register_on_chat_message(function(name, message) +core.register_on_chat_message(function(name, message) local cmd, param = string.match(message, "^/([^ ]+) *(.*)") if not param then param = "" end - local cmd_def = minetest.chatcommands[cmd] + local cmd_def = core.chatcommands[cmd] if cmd_def then - local has_privs, missing_privs = minetest.check_player_privs(name, cmd_def.privs) + local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs) if has_privs then cmd_def.func(name, param) else - minetest.chat_send_player(name, "You don't have permission to run this command (missing privileges: "..table.concat(missing_privs, ", ")..")") + core.chat_send_player(name, "You don't have permission to run this command (missing privileges: "..table.concat(missing_privs, ", ")..")") end return true -- handled chat message end @@ -34,16 +34,16 @@ end) -- -- Chat commands -- -minetest.register_chatcommand("me", { +core.register_chatcommand("me", { params = "", description = "chat action (eg. /me orders a pizza)", privs = {shout=true}, func = function(name, param) - minetest.chat_send_all("* " .. name .. " " .. param) + core.chat_send_all("* " .. name .. " " .. param) end, }) -minetest.register_chatcommand("help", { +core.register_chatcommand("help", { privs = {}, params = "(nothing)/all/privs/", description = "Get help for commands or list privileges", @@ -57,82 +57,82 @@ minetest.register_chatcommand("help", { if param == "" then local msg = "" cmds = {} - for cmd, def in pairs(minetest.chatcommands) do - if minetest.check_player_privs(name, def.privs) then + for cmd, def in pairs(core.chatcommands) do + if core.check_player_privs(name, def.privs) then table.insert(cmds, cmd) end end - minetest.chat_send_player(name, "Available commands: "..table.concat(cmds, " ")) - minetest.chat_send_player(name, "Use '/help ' to get more information, or '/help all' to list everything.") + core.chat_send_player(name, "Available commands: "..table.concat(cmds, " ")) + core.chat_send_player(name, "Use '/help ' to get more information, or '/help all' to list everything.") elseif param == "all" then - minetest.chat_send_player(name, "Available commands:") - for cmd, def in pairs(minetest.chatcommands) do - if minetest.check_player_privs(name, def.privs) then - minetest.chat_send_player(name, format_help_line(cmd, def)) + core.chat_send_player(name, "Available commands:") + for cmd, def in pairs(core.chatcommands) do + if core.check_player_privs(name, def.privs) then + core.chat_send_player(name, format_help_line(cmd, def)) end end elseif param == "privs" then - minetest.chat_send_player(name, "Available privileges:") - for priv, def in pairs(minetest.registered_privileges) do - minetest.chat_send_player(name, priv..": "..def.description) + core.chat_send_player(name, "Available privileges:") + for priv, def in pairs(core.registered_privileges) do + core.chat_send_player(name, priv..": "..def.description) end else local cmd = param - def = minetest.chatcommands[cmd] + def = core.chatcommands[cmd] if not def then - minetest.chat_send_player(name, "Command not available: "..cmd) + core.chat_send_player(name, "Command not available: "..cmd) else - minetest.chat_send_player(name, format_help_line(cmd, def)) + core.chat_send_player(name, format_help_line(cmd, def)) end end end, }) -minetest.register_chatcommand("privs", { +core.register_chatcommand("privs", { params = "", description = "print out privileges of player", func = function(name, param) if param == "" then param = name else - --[[if not minetest.check_player_privs(name, {privs=true}) then - minetest.chat_send_player(name, "Privileges of "..param.." are hidden from you.") + --[[if not core.check_player_privs(name, {privs=true}) then + core.chat_send_player(name, "Privileges of "..param.." are hidden from you.") return end]] end - minetest.chat_send_player(name, "Privileges of "..param..": "..minetest.privs_to_string(minetest.get_player_privs(param), ' ')) + core.chat_send_player(name, "Privileges of "..param..": "..core.privs_to_string(core.get_player_privs(param), ' ')) end, }) -minetest.register_chatcommand("grant", { +core.register_chatcommand("grant", { params = " |all", description = "Give privilege to player", privs = {}, func = function(name, param) - if not minetest.check_player_privs(name, {privs=true}) and - not minetest.check_player_privs(name, {basic_privs=true}) then - minetest.chat_send_player(name, "Your privileges are insufficient.") + if not core.check_player_privs(name, {privs=true}) and + not core.check_player_privs(name, {basic_privs=true}) then + core.chat_send_player(name, "Your privileges are insufficient.") return end local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)") if not grantname or not grantprivstr then - minetest.chat_send_player(name, "Invalid parameters (see /help grant)") + core.chat_send_player(name, "Invalid parameters (see /help grant)") return - elseif not minetest.auth_table[grantname] then - minetest.chat_send_player(name, "Player "..grantname.." does not exist.") + elseif not core.auth_table[grantname] then + core.chat_send_player(name, "Player "..grantname.." does not exist.") return end - local grantprivs = minetest.string_to_privs(grantprivstr) + local grantprivs = core.string_to_privs(grantprivstr) if grantprivstr == "all" then - grantprivs = minetest.registered_privileges + grantprivs = core.registered_privileges end - local privs = minetest.get_player_privs(grantname) + local privs = core.get_player_privs(grantname) local privs_known = true for priv, _ in pairs(grantprivs) do - if priv ~= "interact" and priv ~= "shout" and priv ~= "interact_extra" and not minetest.check_player_privs(name, {privs=true}) then - minetest.chat_send_player(name, "Your privileges are insufficient.") + if priv ~= "interact" and priv ~= "shout" and priv ~= "interact_extra" and not core.check_player_privs(name, {privs=true}) then + core.chat_send_player(name, "Your privileges are insufficient.") return end - if not minetest.registered_privileges[priv] then - minetest.chat_send_player(name, "Unknown privilege: "..priv) + if not core.registered_privileges[priv] then + core.chat_send_player(name, "Unknown privilege: "..priv) privs_known = false end privs[priv] = true @@ -140,37 +140,37 @@ minetest.register_chatcommand("grant", { if not privs_known then return end - minetest.set_player_privs(grantname, privs) - minetest.log(name..' granted ('..minetest.privs_to_string(grantprivs, ', ')..') privileges to '..grantname) - minetest.chat_send_player(name, "Privileges of "..grantname..": "..minetest.privs_to_string(minetest.get_player_privs(grantname), ' ')) + core.set_player_privs(grantname, privs) + core.log(name..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname) + core.chat_send_player(name, "Privileges of "..grantname..": "..core.privs_to_string(core.get_player_privs(grantname), ' ')) if grantname ~= name then - minetest.chat_send_player(grantname, name.." granted you privileges: "..minetest.privs_to_string(grantprivs, ' ')) + core.chat_send_player(grantname, name.." granted you privileges: "..core.privs_to_string(grantprivs, ' ')) end end, }) -minetest.register_chatcommand("revoke", { +core.register_chatcommand("revoke", { params = " |all", description = "Remove privilege from player", privs = {}, func = function(name, param) - if not minetest.check_player_privs(name, {privs=true}) and - not minetest.check_player_privs(name, {basic_privs=true}) then - minetest.chat_send_player(name, "Your privileges are insufficient.") + if not core.check_player_privs(name, {privs=true}) and + not core.check_player_privs(name, {basic_privs=true}) then + core.chat_send_player(name, "Your privileges are insufficient.") return end local revokename, revokeprivstr = string.match(param, "([^ ]+) (.+)") if not revokename or not revokeprivstr then - minetest.chat_send_player(name, "Invalid parameters (see /help revoke)") + core.chat_send_player(name, "Invalid parameters (see /help revoke)") return - elseif not minetest.auth_table[revokename] then - minetest.chat_send_player(name, "Player "..revokename.." does not exist.") + elseif not core.auth_table[revokename] then + core.chat_send_player(name, "Player "..revokename.." does not exist.") return end - local revokeprivs = minetest.string_to_privs(revokeprivstr) - local privs = minetest.get_player_privs(revokename) + local revokeprivs = core.string_to_privs(revokeprivstr) + local privs = core.get_player_privs(revokename) for priv, _ in pairs(revokeprivs) do - if priv ~= "interact" and priv ~= "shout" and priv ~= "interact_extra" and not minetest.check_player_privs(name, {privs=true}) then - minetest.chat_send_player(name, "Your privileges are insufficient.") + if priv ~= "interact" and priv ~= "shout" and priv ~= "interact_extra" and not core.check_player_privs(name, {privs=true}) then + core.chat_send_player(name, "Your privileges are insufficient.") return end end @@ -181,15 +181,15 @@ minetest.register_chatcommand("revoke", { privs[priv] = nil end end - minetest.set_player_privs(revokename, privs) - minetest.log(name..' revoked ('..minetest.privs_to_string(revokeprivs, ', ')..') privileges from '..revokename) - minetest.chat_send_player(name, "Privileges of "..revokename..": "..minetest.privs_to_string(minetest.get_player_privs(revokename), ' ')) + core.set_player_privs(revokename, privs) + core.log(name..' revoked ('..core.privs_to_string(revokeprivs, ', ')..') privileges from '..revokename) + core.chat_send_player(name, "Privileges of "..revokename..": "..core.privs_to_string(core.get_player_privs(revokename), ' ')) if revokename ~= name then - minetest.chat_send_player(revokename, name.." revoked privileges from you: "..minetest.privs_to_string(revokeprivs, ' ')) + core.chat_send_player(revokename, name.." revoked privileges from you: "..core.privs_to_string(revokeprivs, ' ')) end end, }) -minetest.register_chatcommand("setpassword", { +core.register_chatcommand("setpassword", { params = " ", description = "set given password", privs = {password=true}, @@ -200,53 +200,53 @@ minetest.register_chatcommand("setpassword", { raw_password = nil end if not toname then - minetest.chat_send_player(name, "Name field required") + core.chat_send_player(name, "Name field required") return end local actstr = "?" if not raw_password then - minetest.set_player_password(toname, "") + core.set_player_password(toname, "") actstr = "cleared" else - minetest.set_player_password(toname, minetest.get_password_hash(toname, raw_password)) + core.set_player_password(toname, core.get_password_hash(toname, raw_password)) actstr = "set" end - minetest.chat_send_player(name, "Password of player \""..toname.."\" "..actstr) + core.chat_send_player(name, "Password of player \""..toname.."\" "..actstr) if toname ~= name then - minetest.chat_send_player(toname, "Your password was "..actstr.." by "..name) + core.chat_send_player(toname, "Your password was "..actstr.." by "..name) end end, }) -minetest.register_chatcommand("clearpassword", { +core.register_chatcommand("clearpassword", { params = "", description = "set empty password", privs = {password=true}, func = function(name, param) toname = param if toname == "" then - minetest.chat_send_player(name, "Name field required") + core.chat_send_player(name, "Name field required") return end - minetest.set_player_password(toname, '') - minetest.chat_send_player(name, "Password of player \""..toname.."\" cleared") + core.set_player_password(toname, '') + core.chat_send_player(name, "Password of player \""..toname.."\" cleared") end, }) -minetest.register_chatcommand("auth_reload", { +core.register_chatcommand("auth_reload", { params = "", description = "reload authentication data", privs = {server=true}, func = function(name, param) - local done = minetest.auth_reload() + local done = core.auth_reload() if done then - minetest.chat_send_player(name, "Done.") + core.chat_send_player(name, "Done.") else - minetest.chat_send_player(name, "Failed.") + core.chat_send_player(name, "Failed.") end end, }) -minetest.register_chatcommand("teleport", { +core.register_chatcommand("teleport", { params = ",, | | ,, | ", description = "teleport to given position", privs = {teleport=true}, @@ -261,9 +261,9 @@ minetest.register_chatcommand("teleport", { } for _, d in ipairs(tries) do local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z} - local n = minetest.get_node_or_nil(p) + local n = core.get_node_or_nil(p) if n and n.name then - local def = minetest.registered_nodes[n.name] + local def = core.registered_nodes[n.name] if def and not def.walkable then return p, true end @@ -278,9 +278,9 @@ minetest.register_chatcommand("teleport", { p.x = tonumber(p.x) p.y = tonumber(p.y) p.z = tonumber(p.z) - teleportee = minetest.get_player_by_name(name) + teleportee = core.get_player_by_name(name) if teleportee and p.x and p.y and p.z then - minetest.chat_send_player(name, "Teleporting to ("..p.x..", "..p.y..", "..p.z..")") + core.chat_send_player(name, "Teleporting to ("..p.x..", "..p.y..", "..p.z..")") teleportee:setpos(p) return end @@ -289,21 +289,21 @@ minetest.register_chatcommand("teleport", { local p = nil local target_name = nil target_name = string.match(param, "^([^ ]+)$") - teleportee = minetest.get_player_by_name(name) + teleportee = core.get_player_by_name(name) if target_name then - local target = minetest.get_player_by_name(target_name) + local target = core.get_player_by_name(target_name) if target then p = target:getpos() end end if teleportee and p then p = find_free_position_near(p) - minetest.chat_send_player(name, "Teleporting to "..target_name.." at ("..p.x..", "..p.y..", "..p.z..")") + core.chat_send_player(name, "Teleporting to "..target_name.." at ("..p.x..", "..p.y..", "..p.z..")") teleportee:setpos(p) return end - if minetest.check_player_privs(name, {bring=true}) then + if core.check_player_privs(name, {bring=true}) then local teleportee = nil local p = {} local teleportee_name = nil @@ -312,10 +312,10 @@ minetest.register_chatcommand("teleport", { p.y = tonumber(p.y) p.z = tonumber(p.z) if teleportee_name then - teleportee = minetest.get_player_by_name(teleportee_name) + teleportee = core.get_player_by_name(teleportee_name) end if teleportee and p.x and p.y and p.z then - minetest.chat_send_player(name, "Teleporting "..teleportee_name.." to ("..p.x..", "..p.y..", "..p.z..")") + core.chat_send_player(name, "Teleporting "..teleportee_name.." to ("..p.x..", "..p.y..", "..p.z..")") teleportee:setpos(p) return end @@ -326,68 +326,68 @@ minetest.register_chatcommand("teleport", { local target_name = nil teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$") if teleportee_name then - teleportee = minetest.get_player_by_name(teleportee_name) + teleportee = core.get_player_by_name(teleportee_name) end if target_name then - local target = minetest.get_player_by_name(target_name) + local target = core.get_player_by_name(target_name) if target then p = target:getpos() end end if teleportee and p then p = find_free_position_near(p) - minetest.chat_send_player(name, "Teleporting "..teleportee_name.." to "..target_name.." at ("..p.x..", "..p.y..", "..p.z..")") + core.chat_send_player(name, "Teleporting "..teleportee_name.." to "..target_name.." at ("..p.x..", "..p.y..", "..p.z..")") teleportee:setpos(p) return end end - minetest.chat_send_player(name, "Invalid parameters (\""..param.."\") or player not found (see /help teleport)") + core.chat_send_player(name, "Invalid parameters (\""..param.."\") or player not found (see /help teleport)") return end, }) -minetest.register_chatcommand("set", { +core.register_chatcommand("set", { params = "[-n] | ", description = "set or read server configuration setting", privs = {server=true}, func = function(name, param) local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)") if arg and arg == "-n" and setname and setvalue then - minetest.setting_set(setname, setvalue) - minetest.chat_send_player(name, setname.." = "..setvalue) + core.setting_set(setname, setvalue) + core.chat_send_player(name, setname.." = "..setvalue) return end local setname, setvalue = string.match(param, "([^ ]+) (.+)") if setname and setvalue then - if not minetest.setting_get(setname) then - minetest.chat_send_player(name, "Failed. Use '/set -n ' to create a new setting.") + if not core.setting_get(setname) then + core.chat_send_player(name, "Failed. Use '/set -n ' to create a new setting.") return end - minetest.setting_set(setname, setvalue) - minetest.chat_send_player(name, setname.." = "..setvalue) + core.setting_set(setname, setvalue) + core.chat_send_player(name, setname.." = "..setvalue) return end local setname = string.match(param, "([^ ]+)") if setname then - local setvalue = minetest.setting_get(setname) + local setvalue = core.setting_get(setname) if not setvalue then setvalue = "" end - minetest.chat_send_player(name, setname.." = "..setvalue) + core.chat_send_player(name, setname.." = "..setvalue) return end - minetest.chat_send_player(name, "Invalid parameters (see /help set)") + core.chat_send_player(name, "Invalid parameters (see /help set)") end, }) -minetest.register_chatcommand("mods", { +core.register_chatcommand("mods", { params = "", description = "lists mods installed on the server", privs = {}, func = function(name, param) local response = "" - local modnames = minetest.get_modnames() + local modnames = core.get_modnames() for i, mod in ipairs(modnames) do response = response .. mod -- Add space if not at the end @@ -395,25 +395,25 @@ minetest.register_chatcommand("mods", { response = response .. " " end end - minetest.chat_send_player(name, response) + core.chat_send_player(name, response) end, }) local function handle_give_command(cmd, giver, receiver, stackstring) - minetest.log("action", giver.." invoked "..cmd..', stackstring="' + core.log("action", giver.." invoked "..cmd..', stackstring="' ..stackstring..'"') - minetest.log(cmd..' invoked, stackstring="'..stackstring..'"') + core.log(cmd..' invoked, stackstring="'..stackstring..'"') local itemstack = ItemStack(stackstring) if itemstack:is_empty() then - minetest.chat_send_player(giver, 'error: cannot give an empty item') + core.chat_send_player(giver, 'error: cannot give an empty item') return elseif not itemstack:is_known() then - minetest.chat_send_player(giver, 'error: cannot give an unknown item') + core.chat_send_player(giver, 'error: cannot give an unknown item') return end - local receiverref = minetest.get_player_by_name(receiver) + local receiverref = core.get_player_by_name(receiver) if receiverref == nil then - minetest.chat_send_player(giver, receiver..' is not a known player') + core.chat_send_player(giver, receiver..' is not a known player') return end local leftover = receiverref:get_inventory():add_item("main", itemstack) @@ -428,96 +428,96 @@ local function handle_give_command(cmd, giver, receiver, stackstring) -- entered (e.g. big numbers are always interpreted as 2^16-1). stackstring = itemstack:to_string() if giver == receiver then - minetest.chat_send_player(giver, '"'..stackstring + core.chat_send_player(giver, '"'..stackstring ..'" '..partiality..'added to inventory.'); else - minetest.chat_send_player(giver, '"'..stackstring + core.chat_send_player(giver, '"'..stackstring ..'" '..partiality..'added to '..receiver..'\'s inventory.'); - minetest.chat_send_player(receiver, '"'..stackstring + core.chat_send_player(receiver, '"'..stackstring ..'" '..partiality..'added to inventory.'); end end -minetest.register_chatcommand("give", { +core.register_chatcommand("give", { params = " ", description = "give item to player", privs = {give=true}, func = function(name, param) local toname, itemstring = string.match(param, "^([^ ]+) +(.+)$") if not toname or not itemstring then - minetest.chat_send_player(name, "name and itemstring required") + core.chat_send_player(name, "name and itemstring required") return end handle_give_command("/give", name, toname, itemstring) end, }) -minetest.register_chatcommand("giveme", { +core.register_chatcommand("giveme", { params = "", description = "give item to yourself", privs = {give=true}, func = function(name, param) local itemstring = string.match(param, "(.+)$") if not itemstring then - minetest.chat_send_player(name, "itemstring required") + core.chat_send_player(name, "itemstring required") return end handle_give_command("/giveme", name, name, itemstring) end, }) -minetest.register_chatcommand("spawnentity", { +core.register_chatcommand("spawnentity", { params = "", description = "spawn entity at your position", privs = {give=true, interact=true}, func = function(name, param) local entityname = string.match(param, "(.+)$") if not entityname then - minetest.chat_send_player(name, "entityname required") + core.chat_send_player(name, "entityname required") return end - minetest.log("action", '/spawnentity invoked, entityname="'..entityname..'"') - local player = minetest.get_player_by_name(name) + core.log("action", '/spawnentity invoked, entityname="'..entityname..'"') + local player = core.get_player_by_name(name) if player == nil then - minetest.log("error", "Unable to spawn entity, player is nil") + core.log("error", "Unable to spawn entity, player is nil") return true -- Handled chat message end local p = player:getpos() p.y = p.y + 1 - minetest.add_entity(p, entityname) - minetest.chat_send_player(name, '"'..entityname + core.add_entity(p, entityname) + core.chat_send_player(name, '"'..entityname ..'" spawned.'); end, }) -minetest.register_chatcommand("pulverize", { +core.register_chatcommand("pulverize", { params = "", description = "delete item in hand", privs = {}, func = function(name, param) - local player = minetest.get_player_by_name(name) + local player = core.get_player_by_name(name) if player == nil then - minetest.log("error", "Unable to pulverize, player is nil") + core.log("error", "Unable to pulverize, player is nil") return true -- Handled chat message end if player:get_wielded_item():is_empty() then - minetest.chat_send_player(name, 'Unable to pulverize, no item in hand.') + core.chat_send_player(name, 'Unable to pulverize, no item in hand.') else player:set_wielded_item(nil) - minetest.chat_send_player(name, 'An item was pulverized.') + core.chat_send_player(name, 'An item was pulverized.') end end, }) -- Key = player name -minetest.rollback_punch_callbacks = {} +core.rollback_punch_callbacks = {} -minetest.register_on_punchnode(function(pos, node, puncher) +core.register_on_punchnode(function(pos, node, puncher) local name = puncher:get_player_name() - if minetest.rollback_punch_callbacks[name] then - minetest.rollback_punch_callbacks[name](pos, node, puncher) - minetest.rollback_punch_callbacks[name] = nil + if core.rollback_punch_callbacks[name] then + core.rollback_punch_callbacks[name](pos, node, puncher) + core.rollback_punch_callbacks[name] = nil end end) -minetest.register_chatcommand("rollback_check", { +core.register_chatcommand("rollback_check", { params = "[] [] [limit]", description = "check who has last touched a node or near it, ".. "max. ago (default range=0, seconds=86400=24h, limit=5)", @@ -529,29 +529,29 @@ minetest.register_chatcommand("rollback_check", { seconds = tonumber(seconds) or 86400 limit = tonumber(limit) or 5 if limit > 100 then - minetest.chat_send_player(name, "That limit is too high!") + core.chat_send_player(name, "That limit is too high!") return end - minetest.chat_send_player(name, "Punch a node (range=".. + core.chat_send_player(name, "Punch a node (range=".. range..", seconds="..seconds.."s, limit="..limit..")") - minetest.rollback_punch_callbacks[name] = function(pos, node, puncher) + core.rollback_punch_callbacks[name] = function(pos, node, puncher) local name = puncher:get_player_name() - minetest.chat_send_player(name, "Checking "..minetest.pos_to_string(pos).."...") - local actions = minetest.rollback_get_node_actions(pos, range, seconds, limit) + core.chat_send_player(name, "Checking "..core.pos_to_string(pos).."...") + local actions = core.rollback_get_node_actions(pos, range, seconds, limit) local num_actions = #actions if num_actions == 0 then - minetest.chat_send_player(name, "Nobody has touched the ".. + core.chat_send_player(name, "Nobody has touched the ".. "specified location in "..seconds.." seconds") return end local time = os.time() for i = num_actions, 1, -1 do local action = actions[i] - minetest.chat_send_player(name, + core.chat_send_player(name, ("%s %s %s -> %s %d seconds ago.") :format( - minetest.pos_to_string(action.pos), + core.pos_to_string(action.pos), action.actor, action.oldnode.name, action.newnode.name, @@ -561,7 +561,7 @@ minetest.register_chatcommand("rollback_check", { end, }) -minetest.register_chatcommand("rollback", { +core.register_chatcommand("rollback", { params = " [] | : []", description = "revert actions of a player; default for is 60", privs = {rollback=true}, @@ -571,109 +571,109 @@ minetest.register_chatcommand("rollback", { local player_name = nil player_name, seconds = string.match(param, "([^ ]+) *(%d*)") if not player_name then - minetest.chat_send_player(name, "Invalid parameters. See /help rollback and /help rollback_check") + core.chat_send_player(name, "Invalid parameters. See /help rollback and /help rollback_check") return end target_name = "player:"..player_name end seconds = tonumber(seconds) or 60 - minetest.chat_send_player(name, "Reverting actions of ".. + core.chat_send_player(name, "Reverting actions of ".. target_name.." since "..seconds.." seconds.") - local success, log = minetest.rollback_revert_actions_by( + local success, log = core.rollback_revert_actions_by( target_name, seconds) if #log > 100 then - minetest.chat_send_player(name, "(log is too long to show)") + core.chat_send_player(name, "(log is too long to show)") else for _, line in pairs(log) do - minetest.chat_send_player(name, line) + core.chat_send_player(name, line) end end if success then - minetest.chat_send_player(name, "Reverting actions succeeded.") + core.chat_send_player(name, "Reverting actions succeeded.") else - minetest.chat_send_player(name, "Reverting actions FAILED.") + core.chat_send_player(name, "Reverting actions FAILED.") end end, }) -minetest.register_chatcommand("status", { +core.register_chatcommand("status", { params = "", description = "print server status line", privs = {}, func = function(name, param) - minetest.chat_send_player(name, minetest.get_server_status()) + core.chat_send_player(name, core.get_server_status()) end, }) -minetest.register_chatcommand("time", { +core.register_chatcommand("time", { params = "<0...24000>", description = "set time of day", privs = {settime=true}, func = function(name, param) if param == "" then - minetest.chat_send_player(name, "Missing parameter") + core.chat_send_player(name, "Missing parameter") return end local newtime = tonumber(param) if newtime == nil then - minetest.chat_send_player(name, "Invalid time") + core.chat_send_player(name, "Invalid time") else - minetest.set_timeofday((newtime % 24000) / 24000) - minetest.chat_send_player(name, "Time of day changed.") - minetest.log("action", name .. " sets time " .. newtime) + core.set_timeofday((newtime % 24000) / 24000) + core.chat_send_player(name, "Time of day changed.") + core.log("action", name .. " sets time " .. newtime) end end, }) -minetest.register_chatcommand("shutdown", { +core.register_chatcommand("shutdown", { params = "", description = "shutdown server", privs = {server=true}, func = function(name, param) - minetest.log("action", name .. " shuts down server") - minetest.request_shutdown() - minetest.chat_send_all("*** Server shutting down (operator request).") + core.log("action", name .. " shuts down server") + core.request_shutdown() + core.chat_send_all("*** Server shutting down (operator request).") end, }) -minetest.register_chatcommand("ban", { +core.register_chatcommand("ban", { params = "", description = "ban IP of player", privs = {ban=true}, func = function(name, param) if param == "" then - minetest.chat_send_player(name, "Ban list: " .. minetest.get_ban_list()) + core.chat_send_player(name, "Ban list: " .. core.get_ban_list()) return end - if not minetest.get_player_by_name(param) then - minetest.chat_send_player(name, "No such player") + if not core.get_player_by_name(param) then + core.chat_send_player(name, "No such player") return end - if not minetest.ban_player(param) then - minetest.chat_send_player(name, "Failed to ban player") + if not core.ban_player(param) then + core.chat_send_player(name, "Failed to ban player") else - local desc = minetest.get_ban_description(param) - minetest.chat_send_player(name, "Banned " .. desc .. ".") - minetest.log("action", name .. " bans " .. desc .. ".") + local desc = core.get_ban_description(param) + core.chat_send_player(name, "Banned " .. desc .. ".") + core.log("action", name .. " bans " .. desc .. ".") end end, }) -minetest.register_chatcommand("unban", { +core.register_chatcommand("unban", { params = "", description = "remove IP ban", privs = {ban=true}, func = function(name, param) - if not minetest.unban_player_or_ip(param) then - minetest.chat_send_player(name, "Failed to unban player/IP") + if not core.unban_player_or_ip(param) then + core.chat_send_player(name, "Failed to unban player/IP") else - minetest.chat_send_player(name, "Unbanned " .. param) - minetest.log("action", name .. " unbans " .. param) + core.chat_send_player(name, "Unbanned " .. param) + core.log("action", name .. " unbans " .. param) end end, }) -minetest.register_chatcommand("kick", { +core.register_chatcommand("kick", { params = " [reason]", description = "kick a player", privs = {kick=true}, @@ -682,44 +682,44 @@ minetest.register_chatcommand("kick", { if not tokick then tokick = param end - if not minetest.kick_player(tokick, reason) then - minetest.chat_send_player(name, "Failed to kick player " .. tokick) + if not core.kick_player(tokick, reason) then + core.chat_send_player(name, "Failed to kick player " .. tokick) else - minetest.chat_send_player(name, "kicked " .. tokick) - minetest.log("action", name .. " kicked " .. tokick) + core.chat_send_player(name, "kicked " .. tokick) + core.log("action", name .. " kicked " .. tokick) end end, }) -minetest.register_chatcommand("clearobjects", { +core.register_chatcommand("clearobjects", { params = "", description = "clear all objects in world", privs = {server=true}, func = function(name, param) - minetest.log("action", name .. " clears all objects") - minetest.chat_send_all("Clearing all objects. This may take long. You may experience a timeout. (by " .. name .. ")") - minetest.clear_objects() - minetest.log("action", "object clearing done") - minetest.chat_send_all("*** Cleared all objects.") + core.log("action", name .. " clears all objects") + core.chat_send_all("Clearing all objects. This may take long. You may experience a timeout. (by " .. name .. ")") + core.clear_objects() + core.log("action", "object clearing done") + core.chat_send_all("*** Cleared all objects.") end, }) -minetest.register_chatcommand("msg", { +core.register_chatcommand("msg", { params = " ", description = "Send a private message", privs = {shout=true}, func = function(name, param) local found, _, sendto, message = param:find("^([^%s]+)%s(.+)$") if found then - if minetest.get_player_by_name(sendto) then - minetest.log("action", "PM from "..name.." to "..sendto..": "..message) - minetest.chat_send_player(sendto, "PM from "..name..": "..message) - minetest.chat_send_player(name, "Message sent") + if core.get_player_by_name(sendto) then + core.log("action", "PM from "..name.." to "..sendto..": "..message) + core.chat_send_player(sendto, "PM from "..name..": "..message) + core.chat_send_player(name, "Message sent") else - minetest.chat_send_player(name, "The player "..sendto.." is not online") + core.chat_send_player(name, "The player "..sendto.." is not online") end else - minetest.chat_send_player(name, "Invalid usage, see /help msg") + core.chat_send_player(name, "Invalid usage, see /help msg") end end, }) diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index d8b578d48..bbe68be3e 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -4,38 +4,38 @@ -- Default material types -- function digprop_err() - minetest.log("info", debug.traceback()) - minetest.log("info", "WARNING: The minetest.digprop_* functions are obsolete and need to be replaced by item groups.") + core.log("info", debug.traceback()) + core.log("info", "WARNING: The core.digprop_* functions are obsolete and need to be replaced by item groups.") end -minetest.digprop_constanttime = digprop_err -minetest.digprop_stonelike = digprop_err -minetest.digprop_dirtlike = digprop_err -minetest.digprop_gravellike = digprop_err -minetest.digprop_woodlike = digprop_err -minetest.digprop_leaveslike = digprop_err -minetest.digprop_glasslike = digprop_err +core.digprop_constanttime = digprop_err +core.digprop_stonelike = digprop_err +core.digprop_dirtlike = digprop_err +core.digprop_gravellike = digprop_err +core.digprop_woodlike = digprop_err +core.digprop_leaveslike = digprop_err +core.digprop_glasslike = digprop_err -minetest.node_metadata_inventory_move_allow_all = function() - minetest.log("info", "WARNING: minetest.node_metadata_inventory_move_allow_all is obsolete and does nothing.") +core.node_metadata_inventory_move_allow_all = function() + core.log("info", "WARNING: core.node_metadata_inventory_move_allow_all is obsolete and does nothing.") end -minetest.add_to_creative_inventory = function(itemstring) - minetest.log('info', "WARNING: minetest.add_to_creative_inventory: This function is deprecated and does nothing.") +core.add_to_creative_inventory = function(itemstring) + core.log('info', "WARNING: core.add_to_creative_inventory: This function is deprecated and does nothing.") end -- -- EnvRef -- -minetest.env = {} +core.env = {} local envref_deprecation_message_printed = false -setmetatable(minetest.env, { +setmetatable(core.env, { __index = function(table, key) if not envref_deprecation_message_printed then - minetest.log("info", "WARNING: minetest.env:[...] is deprecated and should be replaced with minetest.[...]") + core.log("info", "WARNING: core.env:[...] is deprecated and should be replaced with core.[...]") envref_deprecation_message_printed = true end - local func = minetest[key] + local func = core[key] if type(func) == "function" then rawset(table, key, function(self, ...) return func(...) @@ -47,7 +47,7 @@ setmetatable(minetest.env, { end }) -function minetest.rollback_get_last_node_actor(pos, range, seconds) - return minetest.rollback_get_node_actions(pos, range, seconds, 1)[1] +function core.rollback_get_last_node_actor(pos, range, seconds) + return core.rollback_get_node_actions(pos, range, seconds, 1)[1] end diff --git a/builtin/game/detached_inventory.lua b/builtin/game/detached_inventory.lua index 3757f1387..e8f03b56c 100644 --- a/builtin/game/detached_inventory.lua +++ b/builtin/game/detached_inventory.lua @@ -1,8 +1,8 @@ -- Minetest: builtin/detached_inventory.lua -minetest.detached_inventories = {} +core.detached_inventories = {} -function minetest.create_detached_inventory(name, callbacks) +function core.create_detached_inventory(name, callbacks) local stuff = {} stuff.name = name if callbacks then @@ -13,7 +13,7 @@ function minetest.create_detached_inventory(name, callbacks) stuff.on_put = callbacks.on_put stuff.on_take = callbacks.on_take end - minetest.detached_inventories[name] = stuff - return minetest.create_detached_inventory_raw(name) + core.detached_inventories[name] = stuff + return core.create_detached_inventory_raw(name) end diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index 93d17221a..1a81916ae 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -4,7 +4,7 @@ -- Falling stuff -- -minetest.register_entity(":__builtin:falling_node", { +core.register_entity(":__builtin:falling_node", { initial_properties = { physical = true, collide_with_objects = false, @@ -26,9 +26,9 @@ minetest.register_entity(":__builtin:falling_node", { end local item_texture = nil local item_type = "" - if minetest.registered_items[itemname] then - item_texture = minetest.registered_items[itemname].inventory_image - item_type = minetest.registered_items[itemname].type + if core.registered_items[itemname] then + item_texture = core.registered_items[itemname].inventory_image + item_type = core.registered_items[itemname].type end prop = { is_visible = true, @@ -53,12 +53,12 @@ minetest.register_entity(":__builtin:falling_node", { -- Turn to actual sand when collides to ground or just move local pos = self.object:getpos() local bcp = {x=pos.x, y=pos.y-0.7, z=pos.z} -- Position of bottom center point - local bcn = minetest.get_node(bcp) - local bcd = minetest.registered_nodes[bcn.name] + local bcn = core.get_node(bcp) + local bcd = core.registered_nodes[bcn.name] -- Note: walkable is in the node definition, not in item groups if not bcd or (bcd.walkable or - (minetest.get_item_group(self.node.name, "float") ~= 0 and + (core.get_item_group(self.node.name, "float") ~= 0 and bcd.liquidtype ~= "none")) then if bcd and bcd.leveled and bcn.name == self.node.name then @@ -66,38 +66,38 @@ minetest.register_entity(":__builtin:falling_node", { if addlevel == nil or addlevel <= 0 then addlevel = bcd.leveled end - if minetest.add_node_level(bcp, addlevel) == 0 then + if core.add_node_level(bcp, addlevel) == 0 then self.object:remove() return end elseif bcd and bcd.buildable_to and - (minetest.get_item_group(self.node.name, "float") == 0 or + (core.get_item_group(self.node.name, "float") == 0 or bcd.liquidtype == "none") then - minetest.remove_node(bcp) + core.remove_node(bcp) return end local np = {x=bcp.x, y=bcp.y+1, z=bcp.z} -- Check what's here - local n2 = minetest.get_node(np) + local n2 = core.get_node(np) -- If it's not air or liquid, remove node and replace it with -- it's drops - if n2.name ~= "air" and (not minetest.registered_nodes[n2.name] or - minetest.registered_nodes[n2.name].liquidtype == "none") then - local drops = minetest.get_node_drops(n2.name, "") - minetest.remove_node(np) + if n2.name ~= "air" and (not core.registered_nodes[n2.name] or + core.registered_nodes[n2.name].liquidtype == "none") then + local drops = core.get_node_drops(n2.name, "") + core.remove_node(np) -- Add dropped items local _, dropped_item for _, dropped_item in ipairs(drops) do - minetest.add_item(np, dropped_item) + core.add_item(np, dropped_item) end -- Run script hook local _, callback - for _, callback in ipairs(minetest.registered_on_dignodes) do + for _, callback in ipairs(core.registered_on_dignodes) do callback(np, n2, nil) end end -- Create node and remove entity - minetest.add_node(np, self.node) + core.add_node(np, self.node) self.object:remove() nodeupdate(np) else @@ -107,25 +107,25 @@ minetest.register_entity(":__builtin:falling_node", { }) function spawn_falling_node(p, node) - obj = minetest.add_entity(p, "__builtin:falling_node") + obj = core.add_entity(p, "__builtin:falling_node") obj:get_luaentity():set_node(node) end function drop_attached_node(p) - local nn = minetest.get_node(p).name - minetest.remove_node(p) - for _,item in ipairs(minetest.get_node_drops(nn, "")) do + local nn = core.get_node(p).name + core.remove_node(p) + for _,item in ipairs(core.get_node_drops(nn, "")) do local pos = { x = p.x + math.random()/2 - 0.25, y = p.y + math.random()/2 - 0.25, z = p.z + math.random()/2 - 0.25, } - minetest.add_item(pos, item) + core.add_item(pos, item) end end function check_attached_node(p, n) - local def = minetest.registered_nodes[n.name] + local def = core.registered_nodes[n.name] local d = {x=0, y=0, z=0} if def.paramtype2 == "wallmounted" then if n.param2 == 0 then @@ -145,8 +145,8 @@ function check_attached_node(p, n) d.y = -1 end local p2 = {x=p.x+d.x, y=p.y+d.y, z=p.z+d.z} - local nn = minetest.get_node(p2).name - local def2 = minetest.registered_nodes[nn] + local nn = core.get_node(p2).name + local def2 = core.registered_nodes[nn] if def2 and not def2.walkable then return false end @@ -158,28 +158,30 @@ end -- function nodeupdate_single(p, delay) - n = minetest.get_node(p) - if minetest.get_item_group(n.name, "falling_node") ~= 0 then + n = core.get_node(p) + if core.get_item_group(n.name, "falling_node") ~= 0 then p_bottom = {x=p.x, y=p.y-1, z=p.z} - n_bottom = minetest.get_node(p_bottom) + n_bottom = core.get_node(p_bottom) -- Note: walkable is in the node definition, not in item groups - if minetest.registered_nodes[n_bottom.name] and - (minetest.get_item_group(n.name, "float") == 0 or minetest.registered_nodes[n_bottom.name].liquidtype == "none") and - (n.name ~= n_bottom.name or (minetest.registered_nodes[n_bottom.name].leveled and minetest.env:get_node_level(p_bottom) < minetest.env:get_node_max_level(p_bottom))) and - (not minetest.registered_nodes[n_bottom.name].walkable or - minetest.registered_nodes[n_bottom.name].buildable_to) then + if core.registered_nodes[n_bottom.name] and + (core.get_item_group(n.name, "float") == 0 or + core.registered_nodes[n_bottom.name].liquidtype == "none") and + (n.name ~= n_bottom.name or (core.registered_nodes[n_bottom.name].leveled and + core.get_node_level(p_bottom) < core.get_node_max_level(p_bottom))) and + (not core.registered_nodes[n_bottom.name].walkable or + core.registered_nodes[n_bottom.name].buildable_to) then if delay then - minetest.after(0.1, nodeupdate_single, {x=p.x, y=p.y, z=p.z}, false) + core.after(0.1, nodeupdate_single, {x=p.x, y=p.y, z=p.z}, false) else - n.level = minetest.env:get_node_level(p) - minetest.remove_node(p) + n.level = core.env:get_node_level(p) + core.remove_node(p) spawn_falling_node(p, n) nodeupdate(p) end end end - if minetest.get_item_group(n.name, "attached_node") ~= 0 then + if core.get_item_group(n.name, "attached_node") ~= 0 then if not check_attached_node(p, n) then drop_attached_node(p) nodeupdate(p) @@ -209,9 +211,9 @@ end function on_placenode(p, node) nodeupdate(p) end -minetest.register_on_placenode(on_placenode) +core.register_on_placenode(on_placenode) function on_dignode(p, node) nodeupdate(p) end -minetest.register_on_dignode(on_dignode) +core.register_on_dignode(on_dignode) diff --git a/builtin/game/features.lua b/builtin/game/features.lua index f3de3ba21..2abfe5278 100644 --- a/builtin/game/features.lua +++ b/builtin/game/features.lua @@ -1,6 +1,6 @@ -- Minetest: builtin/features.lua -minetest.features = { +core.features = { glasslike_framed = true, nodebox_as_selectionbox = true, chat_send_player_param3 = true, @@ -9,19 +9,19 @@ minetest.features = { no_legacy_abms = true, } -function minetest.has_feature(arg) +function core.has_feature(arg) if type(arg) == "table" then missing_features = {} result = true for ft, _ in pairs(arg) do - if not minetest.features[ftr] then + if not core.features[ftr] then missing_features[ftr] = true result = false end end return result, missing_features elseif type(arg) == "string" then - if not minetest.features[arg] then + if not core.features[arg] then return false, {[arg]=true} end return true, {} diff --git a/builtin/game/forceloading.lua b/builtin/game/forceloading.lua index 84895792b..147f12fa0 100644 --- a/builtin/game/forceloading.lua +++ b/builtin/game/forceloading.lua @@ -1,8 +1,8 @@ -- Prevent anyone else accessing those functions -local forceload_block = minetest.forceload_block -local forceload_free_block = minetest.forceload_free_block -minetest.forceload_block = nil -minetest.forceload_free_block = nil +local forceload_block = core.forceload_block +local forceload_free_block = core.forceload_free_block +core.forceload_block = nil +core.forceload_free_block = nil local blocks_forceloaded local total_forceloaded = 0 @@ -15,14 +15,14 @@ local function get_blockpos(pos) z = math.floor(pos.z/BLOCKSIZE)} end -function minetest.forceload_block(pos) +function core.forceload_block(pos) local blockpos = get_blockpos(pos) - local hash = minetest.hash_node_position(blockpos) + local hash = core.hash_node_position(blockpos) if blocks_forceloaded[hash] ~= nil then blocks_forceloaded[hash] = blocks_forceloaded[hash] + 1 return true else - if total_forceloaded >= (tonumber(minetest.setting_get("max_forceloaded_blocks")) or 16) then + if total_forceloaded >= (tonumber(core.setting_get("max_forceloaded_blocks")) or 16) then return false end total_forceloaded = total_forceloaded+1 @@ -32,9 +32,9 @@ function minetest.forceload_block(pos) end end -function minetest.forceload_free_block(pos) +function core.forceload_free_block(pos) local blockpos = get_blockpos(pos) - local hash = minetest.hash_node_position(blockpos) + local hash = core.hash_node_position(blockpos) if blocks_forceloaded[hash] == nil then return end if blocks_forceloaded[hash] > 1 then blocks_forceloaded[hash] = blocks_forceloaded[hash] - 1 @@ -46,19 +46,19 @@ function minetest.forceload_free_block(pos) end -- Keep the forceloaded areas after restart -local wpath = minetest.get_worldpath() +local wpath = core.get_worldpath() local function read_file(filename) local f = io.open(filename, "r") if f==nil then return {} end local t = f:read("*all") f:close() if t=="" or t==nil then return {} end - return minetest.deserialize(t) + return core.deserialize(t) end local function write_file(filename, table) local f = io.open(filename, "w") - f:write(minetest.serialize(table)) + f:write(core.serialize(table)) f:close() end @@ -67,13 +67,13 @@ for _, __ in pairs(blocks_forceloaded) do total_forceloaded = total_forceloaded + 1 end -minetest.after(5, function() +core.after(5, function() for hash, _ in pairs(blocks_forceloaded) do - local blockpos = minetest.get_position_from_hash(hash) + local blockpos = core.get_position_from_hash(hash) forceload_block(blockpos) end end) -minetest.register_on_shutdown(function() +core.register_on_shutdown(function() write_file(wpath.."/force_loaded.txt", blocks_forceloaded) end) diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 002c14f5e..8fd172aab 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -13,7 +13,7 @@ end -- Item definition helpers -- -function minetest.inventorycube(img1, img2, img3) +function core.inventorycube(img1, img2, img3) img2 = img2 or img1 img3 = img3 or img1 return "[inventorycube" @@ -22,7 +22,7 @@ function minetest.inventorycube(img1, img2, img3) .. "{" .. img3:gsub("%^", "&") end -function minetest.get_pointed_thing_position(pointed_thing, above) +function core.get_pointed_thing_position(pointed_thing, above) if pointed_thing.type == "node" then if above then -- The position where a node would be placed @@ -43,7 +43,7 @@ function minetest.get_pointed_thing_position(pointed_thing, above) end end -function minetest.dir_to_facedir(dir, is6d) +function core.dir_to_facedir(dir, is6d) --account for y if requested if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then @@ -96,7 +96,7 @@ function minetest.dir_to_facedir(dir, is6d) end end -function minetest.facedir_to_dir(facedir) +function core.facedir_to_dir(facedir) --a table of possible dirs return ({{x=0, y=0, z=1}, {x=1, y=0, z=0}, @@ -117,7 +117,7 @@ function minetest.facedir_to_dir(facedir) [facedir]] end -function minetest.dir_to_wallmounted(dir) +function core.dir_to_wallmounted(dir) if math.abs(dir.y) > math.max(math.abs(dir.x), math.abs(dir.z)) then if dir.y < 0 then return 1 @@ -139,7 +139,7 @@ function minetest.dir_to_wallmounted(dir) end end -function minetest.get_node_drops(nodename, toolname) +function core.get_node_drops(nodename, toolname) local drop = ItemStack({name=nodename}):get_definition().drop if drop == nil then -- default drop @@ -188,7 +188,7 @@ function minetest.get_node_drops(nodename, toolname) return got_items end -function minetest.item_place_node(itemstack, placer, pointed_thing, param2) +function core.item_place_node(itemstack, placer, pointed_thing, param2) local item = itemstack:peek_item() local def = itemstack:get_definition() if def.type ~= "node" or pointed_thing.type ~= "node" then @@ -196,24 +196,24 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2) end local under = pointed_thing.under - local oldnode_under = minetest.get_node_or_nil(under) + local oldnode_under = core.get_node_or_nil(under) local above = pointed_thing.above - local oldnode_above = minetest.get_node_or_nil(above) + local oldnode_above = core.get_node_or_nil(above) if not oldnode_under or not oldnode_above then - minetest.log("info", placer:get_player_name() .. " tried to place" - .. " node in unloaded position " .. minetest.pos_to_string(above)) + core.log("info", placer:get_player_name() .. " tried to place" + .. " node in unloaded position " .. core.pos_to_string(above)) return itemstack, false end local olddef_under = ItemStack({name=oldnode_under.name}):get_definition() - olddef_under = olddef_under or minetest.nodedef_default + olddef_under = olddef_under or core.nodedef_default local olddef_above = ItemStack({name=oldnode_above.name}):get_definition() - olddef_above = olddef_above or minetest.nodedef_default + olddef_above = olddef_above or core.nodedef_default if not olddef_above.buildable_to and not olddef_under.buildable_to then - minetest.log("info", placer:get_player_name() .. " tried to place" - .. " node in invalid position " .. minetest.pos_to_string(above) + core.log("info", placer:get_player_name() .. " tried to place" + .. " node in invalid position " .. core.pos_to_string(above) .. ", replacing " .. oldnode_above.name) return itemstack, false end @@ -223,23 +223,23 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2) -- If node under is buildable_to, place into it instead (eg. snow) if olddef_under.buildable_to then - minetest.log("info", "node under is buildable to") + core.log("info", "node under is buildable to") place_to = {x = under.x, y = under.y, z = under.z} end - if minetest.is_protected(place_to, placer:get_player_name()) then - minetest.log("action", placer:get_player_name() + if core.is_protected(place_to, placer:get_player_name()) then + core.log("action", placer:get_player_name() .. " tried to place " .. def.name .. " at protected position " - .. minetest.pos_to_string(place_to)) - minetest.record_protection_violation(place_to, placer:get_player_name()) + .. core.pos_to_string(place_to)) + core.record_protection_violation(place_to, placer:get_player_name()) return itemstack end - minetest.log("action", placer:get_player_name() .. " places node " - .. def.name .. " at " .. minetest.pos_to_string(place_to)) + core.log("action", placer:get_player_name() .. " places node " + .. def.name .. " at " .. core.pos_to_string(place_to)) - local oldnode = minetest.get_node(place_to) + local oldnode = core.get_node(place_to) local newnode = {name = def.name, param1 = 0, param2 = param2} -- Calculate direction for wall mounted stuff like torches and signs @@ -249,7 +249,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2) y = under.y - above.y, z = under.z - above.z } - newnode.param2 = minetest.dir_to_wallmounted(dir) + newnode.param2 = core.dir_to_wallmounted(dir) -- Calculate the direction for furnaces and chests and stuff elseif def.paramtype2 == 'facedir' and not param2 then local placer_pos = placer:getpos() @@ -259,21 +259,21 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2) y = above.y - placer_pos.y, z = above.z - placer_pos.z } - newnode.param2 = minetest.dir_to_facedir(dir) - minetest.log("action", "facedir: " .. newnode.param2) + newnode.param2 = core.dir_to_facedir(dir) + core.log("action", "facedir: " .. newnode.param2) end end -- Check if the node is attached and if it can be placed there - if minetest.get_item_group(def.name, "attached_node") ~= 0 and + if core.get_item_group(def.name, "attached_node") ~= 0 and not check_attached_node(place_to, newnode) then - minetest.log("action", "attached node " .. def.name .. - " can not be placed at " .. minetest.pos_to_string(place_to)) + core.log("action", "attached node " .. def.name .. + " can not be placed at " .. core.pos_to_string(place_to)) return itemstack, false end -- Add node and update - minetest.add_node(place_to, newnode) + core.add_node(place_to, newnode) local take_item = true @@ -290,7 +290,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2) -- Run script hook local _, callback - for _, callback in ipairs(minetest.registered_on_placenodes) do + for _, callback in ipairs(core.registered_on_placenodes) do -- Deepcopy pos, node and pointed_thing because callback can modify them local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z} local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2} @@ -307,38 +307,38 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2) return itemstack, true end -function minetest.item_place_object(itemstack, placer, pointed_thing) - local pos = minetest.get_pointed_thing_position(pointed_thing, true) +function core.item_place_object(itemstack, placer, pointed_thing) + local pos = core.get_pointed_thing_position(pointed_thing, true) if pos ~= nil then local item = itemstack:take_item() - minetest.add_item(pos, item) + core.add_item(pos, item) end return itemstack end -function minetest.item_place(itemstack, placer, pointed_thing, param2) +function core.item_place(itemstack, placer, pointed_thing, param2) -- Call on_rightclick if the pointed node defines it if pointed_thing.type == "node" and placer and not placer:get_player_control().sneak then - local n = minetest.get_node(pointed_thing.under) + local n = core.get_node(pointed_thing.under) local nn = n.name - if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then - return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n, + if core.registered_nodes[nn] and core.registered_nodes[nn].on_rightclick then + return core.registered_nodes[nn].on_rightclick(pointed_thing.under, n, placer, itemstack, pointed_thing) or itemstack, false end end if itemstack:get_definition().type == "node" then - return minetest.item_place_node(itemstack, placer, pointed_thing, param2) + return core.item_place_node(itemstack, placer, pointed_thing, param2) end return itemstack end -function minetest.item_drop(itemstack, dropper, pos) +function core.item_drop(itemstack, dropper, pos) if dropper.get_player_name then local v = dropper:get_look_dir() local p = {x=pos.x+v.x, y=pos.y+1.5+v.y, z=pos.z+v.z} - local obj = minetest.add_item(p, itemstack) + local obj = core.add_item(p, itemstack) if obj then v.x = v.x*2 v.y = v.y*2 + 1 @@ -346,12 +346,12 @@ function minetest.item_drop(itemstack, dropper, pos) obj:setvelocity(v) end else - minetest.add_item(pos, itemstack) + core.add_item(pos, itemstack) end return ItemStack("") end -function minetest.item_eat(hp_change, replace_with_item) +function core.item_eat(hp_change, replace_with_item) return function(itemstack, user, pointed_thing) -- closure if itemstack:take_item() ~= nil then user:set_hp(user:get_hp() + hp_change) @@ -361,9 +361,9 @@ function minetest.item_eat(hp_change, replace_with_item) end end -function minetest.node_punch(pos, node, puncher, pointed_thing) +function core.node_punch(pos, node, puncher, pointed_thing) -- Run script hook - for _, callback in ipairs(minetest.registered_on_punchnodes) do + for _, callback in ipairs(core.registered_on_punchnodes) do -- Copy pos and node because callback can modify them local pos_copy = vector.new(pos) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} @@ -372,7 +372,7 @@ function minetest.node_punch(pos, node, puncher, pointed_thing) end end -function minetest.handle_node_drops(pos, drops, digger) +function core.handle_node_drops(pos, drops, digger) -- Add dropped items to object's inventory if digger:get_inventory() then local _, dropped_item @@ -384,59 +384,59 @@ function minetest.handle_node_drops(pos, drops, digger) y = pos.y + math.random()/2-0.25, z = pos.z + math.random()/2-0.25, } - minetest.add_item(p, left) + core.add_item(p, left) end end end end -function minetest.node_dig(pos, node, digger) +function core.node_dig(pos, node, digger) local def = ItemStack({name=node.name}):get_definition() if not def.diggable or (def.can_dig and not def.can_dig(pos,digger)) then - minetest.log("info", digger:get_player_name() .. " tried to dig " + core.log("info", digger:get_player_name() .. " tried to dig " .. node.name .. " which is not diggable " - .. minetest.pos_to_string(pos)) + .. core.pos_to_string(pos)) return end - if minetest.is_protected(pos, digger:get_player_name()) then - minetest.log("action", digger:get_player_name() + if core.is_protected(pos, digger:get_player_name()) then + core.log("action", digger:get_player_name() .. " tried to dig " .. node.name .. " at protected position " - .. minetest.pos_to_string(pos)) - minetest.record_protection_violation(pos, digger:get_player_name()) + .. core.pos_to_string(pos)) + core.record_protection_violation(pos, digger:get_player_name()) return end - minetest.log('action', digger:get_player_name() .. " digs " - .. node.name .. " at " .. minetest.pos_to_string(pos)) + core.log('action', digger:get_player_name() .. " digs " + .. node.name .. " at " .. core.pos_to_string(pos)) local wielded = digger:get_wielded_item() - local drops = minetest.get_node_drops(node.name, wielded:get_name()) + local drops = core.get_node_drops(node.name, wielded:get_name()) local wdef = wielded:get_definition() local tp = wielded:get_tool_capabilities() - local dp = minetest.get_dig_params(def.groups, tp) + local dp = core.get_dig_params(def.groups, tp) if wdef and wdef.after_use then wielded = wdef.after_use(wielded, digger, node, dp) or wielded else -- Wear out tool - if not minetest.setting_getbool("creative_mode") then + if not core.setting_getbool("creative_mode") then wielded:add_wear(dp.wear) end end digger:set_wielded_item(wielded) -- Handle drops - minetest.handle_node_drops(pos, drops, digger) + core.handle_node_drops(pos, drops, digger) local oldmetadata = nil if def.after_dig_node then - oldmetadata = minetest.get_meta(pos):to_table() + oldmetadata = core.get_meta(pos):to_table() end -- Remove node and update - minetest.remove_node(pos) + core.remove_node(pos) -- Run callback if def.after_dig_node then @@ -448,7 +448,7 @@ function minetest.node_dig(pos, node, digger) -- Run script hook local _, callback - for _, callback in ipairs(minetest.registered_on_dignodes) do + for _, callback in ipairs(core.registered_on_dignodes) do -- Copy pos and node because callback can modify them local pos_copy = {x=pos.x, y=pos.y, z=pos.z} local node_copy = {name=node.name, param1=node.param1, param2=node.param2} @@ -456,7 +456,7 @@ function minetest.node_dig(pos, node, digger) end end --- This is used to allow mods to redefine minetest.item_place and so on +-- This is used to allow mods to redefine core.item_place and so on -- NOTE: This is not the preferred way. Preferred way is to provide enough -- callbacks to not require redefining global functions. -celeron55 local function redef_wrapper(table, name) @@ -469,7 +469,7 @@ end -- Item definition defaults -- -minetest.nodedef_default = { +core.nodedef_default = { -- Item properties type="node", -- name intentionally not defined here @@ -485,20 +485,20 @@ minetest.nodedef_default = { node_placement_prediction = nil, -- Interaction callbacks - on_place = redef_wrapper(minetest, 'item_place'), -- minetest.item_place - on_drop = redef_wrapper(minetest, 'item_drop'), -- minetest.item_drop + on_place = redef_wrapper(core, 'item_place'), -- core.item_place + on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop on_use = nil, can_dig = nil, - on_punch = redef_wrapper(minetest, 'node_punch'), -- minetest.node_punch + on_punch = redef_wrapper(core, 'node_punch'), -- core.node_punch on_rightclick = nil, - on_dig = redef_wrapper(minetest, 'node_dig'), -- minetest.node_dig + on_dig = redef_wrapper(core, 'node_dig'), -- core.node_dig on_receive_fields = nil, - on_metadata_inventory_move = minetest.node_metadata_inventory_move_allow_all, - on_metadata_inventory_offer = minetest.node_metadata_inventory_offer_allow_all, - on_metadata_inventory_take = minetest.node_metadata_inventory_take_allow_all, + on_metadata_inventory_move = core.node_metadata_inventory_move_allow_all, + on_metadata_inventory_offer = core.node_metadata_inventory_offer_allow_all, + on_metadata_inventory_take = core.node_metadata_inventory_take_allow_all, -- Node properties drawtype = "normal", @@ -533,7 +533,7 @@ minetest.nodedef_default = { legacy_wallmounted = false, } -minetest.craftitemdef_default = { +core.craftitemdef_default = { type="craft", -- name intentionally not defined here description = "", @@ -546,12 +546,12 @@ minetest.craftitemdef_default = { tool_capabilities = nil, -- Interaction callbacks - on_place = redef_wrapper(minetest, 'item_place'), -- minetest.item_place - on_drop = redef_wrapper(minetest, 'item_drop'), -- minetest.item_drop + on_place = redef_wrapper(core, 'item_place'), -- core.item_place + on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop on_use = nil, } -minetest.tooldef_default = { +core.tooldef_default = { type="tool", -- name intentionally not defined here description = "", @@ -564,12 +564,12 @@ minetest.tooldef_default = { tool_capabilities = nil, -- Interaction callbacks - on_place = redef_wrapper(minetest, 'item_place'), -- minetest.item_place - on_drop = redef_wrapper(minetest, 'item_drop'), -- minetest.item_drop + on_place = redef_wrapper(core, 'item_place'), -- core.item_place + on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop on_use = nil, } -minetest.noneitemdef_default = { -- This is used for the hand and unknown items +core.noneitemdef_default = { -- This is used for the hand and unknown items type="none", -- name intentionally not defined here description = "", @@ -582,7 +582,7 @@ minetest.noneitemdef_default = { -- This is used for the hand and unknown items tool_capabilities = nil, -- Interaction callbacks - on_place = redef_wrapper(minetest, 'item_place'), + on_place = redef_wrapper(core, 'item_place'), on_drop = nil, on_use = nil, } diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua index 8150e6da1..4f6988c00 100644 --- a/builtin/game/item_entity.lua +++ b/builtin/game/item_entity.lua @@ -1,14 +1,14 @@ -- Minetest: builtin/item_entity.lua -function minetest.spawn_item(pos, item) +function core.spawn_item(pos, item) -- Take item in any format local stack = ItemStack(item) - local obj = minetest.add_entity(pos, "__builtin:item") + local obj = core.add_entity(pos, "__builtin:item") obj:get_luaentity():set_item(stack:to_string()) return obj end -minetest.register_entity(":__builtin:item", { +core.register_entity(":__builtin:item", { initial_properties = { hp_max = 1, physical = true, @@ -35,9 +35,9 @@ minetest.register_entity(":__builtin:item", { end local item_texture = nil local item_type = "" - if minetest.registered_items[itemname] then - item_texture = minetest.registered_items[itemname].inventory_image - item_type = minetest.registered_items[itemname].type + if core.registered_items[itemname] then + item_texture = core.registered_items[itemname].inventory_image + item_type = core.registered_items[itemname].type end prop = { is_visible = true, @@ -59,7 +59,7 @@ minetest.register_entity(":__builtin:item", { get_staticdata = function(self) --return self.itemstring - return minetest.serialize({ + return core.serialize({ itemstring = self.itemstring, always_collect = self.always_collect, }) @@ -67,7 +67,7 @@ minetest.register_entity(":__builtin:item", { on_activate = function(self, staticdata) if string.sub(staticdata, 1, string.len("return")) == "return" then - local data = minetest.deserialize(staticdata) + local data = core.deserialize(staticdata) if data and type(data) == "table" then self.itemstring = data.itemstring self.always_collect = data.always_collect @@ -84,10 +84,10 @@ minetest.register_entity(":__builtin:item", { on_step = function(self, dtime) local p = self.object:getpos() p.y = p.y - 0.3 - local nn = minetest.get_node(p).name + local nn = core.get_node(p).name -- If node is not registered or node is walkably solid and resting on nodebox local v = self.object:getvelocity() - if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and v.y == 0 then + if not core.registered_nodes[nn] or core.registered_nodes[nn].walkable and v.y == 0 then if self.physical_state then self.object:setvelocity({x=0,y=0,z=0}) self.object:setacceleration({x=0, y=0, z=0}) diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua index 82cc527cd..4afcdb99e 100644 --- a/builtin/game/misc.lua +++ b/builtin/game/misc.lua @@ -4,30 +4,30 @@ -- Misc. API functions -- -minetest.timers_to_add = {} -minetest.timers = {} -minetest.register_globalstep(function(dtime) - for _, timer in ipairs(minetest.timers_to_add) do - table.insert(minetest.timers, timer) +core.timers_to_add = {} +core.timers = {} +core.register_globalstep(function(dtime) + for _, timer in ipairs(core.timers_to_add) do + table.insert(core.timers, timer) end - minetest.timers_to_add = {} - for index, timer in ipairs(minetest.timers) do + core.timers_to_add = {} + for index, timer in ipairs(core.timers) do timer.time = timer.time - dtime if timer.time <= 0 then timer.func(unpack(timer.args or {})) - table.remove(minetest.timers,index) + table.remove(core.timers,index) end end end) -function minetest.after(time, func, ...) +function core.after(time, func, ...) assert(tonumber(time) and type(func) == "function", - "Invalid minetest.after invocation") - table.insert(minetest.timers_to_add, {time=time, func=func, args={...}}) + "Invalid core.after invocation") + table.insert(core.timers_to_add, {time=time, func=func, args={...}}) end -function minetest.check_player_privs(name, privs) - local player_privs = minetest.get_player_privs(name) +function core.check_player_privs(name, privs) + local player_privs = core.get_player_privs(name) local missing_privileges = {} for priv, val in pairs(privs) do if val then @@ -44,15 +44,15 @@ end local player_list = {} -minetest.register_on_joinplayer(function(player) +core.register_on_joinplayer(function(player) player_list[player:get_player_name()] = player end) -minetest.register_on_leaveplayer(function(player) +core.register_on_leaveplayer(function(player) player_list[player:get_player_name()] = nil end) -function minetest.get_connected_players() +function core.get_connected_players() local temp_table = {} for index, value in pairs(player_list) do if value:is_player_connected() then @@ -62,11 +62,11 @@ function minetest.get_connected_players() return temp_table end -function minetest.hash_node_position(pos) +function core.hash_node_position(pos) return (pos.z+32768)*65536*65536 + (pos.y+32768)*65536 + pos.x+32768 end -function minetest.get_position_from_hash(hash) +function core.get_position_from_hash(hash) local pos = {} pos.x = (hash%65536) - 32768 hash = math.floor(hash/65536) @@ -76,20 +76,20 @@ function minetest.get_position_from_hash(hash) return pos end -function minetest.get_item_group(name, group) - if not minetest.registered_items[name] or not - minetest.registered_items[name].groups[group] then +function core.get_item_group(name, group) + if not core.registered_items[name] or not + core.registered_items[name].groups[group] then return 0 end - return minetest.registered_items[name].groups[group] + return core.registered_items[name].groups[group] end -function minetest.get_node_group(name, group) - minetest.log("deprecated", "Deprecated usage of get_node_group, use get_item_group instead") - return minetest.get_item_group(name, group) +function core.get_node_group(name, group) + core.log("deprecated", "Deprecated usage of get_node_group, use get_item_group instead") + return core.get_item_group(name, group) end -function minetest.string_to_pos(value) +function core.string_to_pos(value) local p = {} p.x, p.y, p.z = string.match(value, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$") if p.x and p.y and p.z then @@ -109,25 +109,25 @@ function minetest.string_to_pos(value) return nil end -assert(minetest.string_to_pos("10.0, 5, -2").x == 10) -assert(minetest.string_to_pos("( 10.0, 5, -2)").z == -2) -assert(minetest.string_to_pos("asd, 5, -2)") == nil) +assert(core.string_to_pos("10.0, 5, -2").x == 10) +assert(core.string_to_pos("( 10.0, 5, -2)").z == -2) +assert(core.string_to_pos("asd, 5, -2)") == nil) -function minetest.setting_get_pos(name) - local value = minetest.setting_get(name) +function core.setting_get_pos(name) + local value = core.setting_get(name) if not value then return nil end - return minetest.string_to_pos(value) + return core.string_to_pos(value) end -- To be overriden by protection mods -function minetest.is_protected(pos, name) +function core.is_protected(pos, name) return false end -function minetest.record_protection_violation(pos, name) - for _, func in pairs(minetest.registered_on_protection_violation) do +function core.record_protection_violation(pos, name) + for _, func in pairs(core.registered_on_protection_violation) do func(pos, name) end end diff --git a/builtin/game/privileges.lua b/builtin/game/privileges.lua index 244aa453c..7e6387c72 100644 --- a/builtin/game/privileges.lua +++ b/builtin/game/privileges.lua @@ -4,9 +4,9 @@ -- Privileges -- -minetest.registered_privileges = {} +core.registered_privileges = {} -function minetest.register_privilege(name, param) +function core.register_privilege(name, param) local function fill_defaults(def) if def.give_to_singleplayer == nil then def.give_to_singleplayer = true @@ -22,32 +22,32 @@ function minetest.register_privilege(name, param) def = {description = param} end fill_defaults(def) - minetest.registered_privileges[name] = def + core.registered_privileges[name] = def end -minetest.register_privilege("interact", "Can interact with things and modify the world") -minetest.register_privilege("teleport", "Can use /teleport command") -minetest.register_privilege("bring", "Can teleport other players") -minetest.register_privilege("settime", "Can use /time") -minetest.register_privilege("privs", "Can modify privileges") -minetest.register_privilege("basic_privs", "Can modify 'shout' and 'interact' privileges") -minetest.register_privilege("server", "Can do server maintenance stuff") -minetest.register_privilege("shout", "Can speak in chat") -minetest.register_privilege("ban", "Can ban and unban players") -minetest.register_privilege("kick", "Can kick players") -minetest.register_privilege("give", "Can use /give and /giveme") -minetest.register_privilege("password", "Can use /setpassword and /clearpassword") -minetest.register_privilege("fly", { +core.register_privilege("interact", "Can interact with things and modify the world") +core.register_privilege("teleport", "Can use /teleport command") +core.register_privilege("bring", "Can teleport other players") +core.register_privilege("settime", "Can use /time") +core.register_privilege("privs", "Can modify privileges") +core.register_privilege("basic_privs", "Can modify 'shout' and 'interact' privileges") +core.register_privilege("server", "Can do server maintenance stuff") +core.register_privilege("shout", "Can speak in chat") +core.register_privilege("ban", "Can ban and unban players") +core.register_privilege("kick", "Can kick players") +core.register_privilege("give", "Can use /give and /giveme") +core.register_privilege("password", "Can use /setpassword and /clearpassword") +core.register_privilege("fly", { description = "Can fly using the free_move mode", give_to_singleplayer = false, }) -minetest.register_privilege("fast", { +core.register_privilege("fast", { description = "Can walk fast using the fast_move mode", give_to_singleplayer = false, }) -minetest.register_privilege("noclip", { +core.register_privilege("noclip", { description = "Can fly through walls", give_to_singleplayer = false, }) -minetest.register_privilege("rollback", "Can use the rollback functionality") +core.register_privilege("rollback", "Can use the rollback functionality") diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 99c5115c4..8908f51f6 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -4,35 +4,35 @@ -- Make raw registration functions inaccessible to anyone except this file -- -local register_item_raw = minetest.register_item_raw -minetest.register_item_raw = nil +local register_item_raw = core.register_item_raw +core.register_item_raw = nil -local register_alias_raw = minetest.register_alias_raw -minetest.register_item_raw = nil +local register_alias_raw = core.register_alias_raw +core.register_item_raw = nil -- -- Item / entity / ABM registration functions -- -minetest.registered_abms = {} -minetest.registered_entities = {} -minetest.registered_items = {} -minetest.registered_nodes = {} -minetest.registered_craftitems = {} -minetest.registered_tools = {} -minetest.registered_aliases = {} +core.registered_abms = {} +core.registered_entities = {} +core.registered_items = {} +core.registered_nodes = {} +core.registered_craftitems = {} +core.registered_tools = {} +core.registered_aliases = {} -- For tables that are indexed by item name: --- If table[X] does not exist, default to table[minetest.registered_aliases[X]] +-- If table[X] does not exist, default to table[core.registered_aliases[X]] local alias_metatable = { __index = function(t, name) - return rawget(t, minetest.registered_aliases[name]) + return rawget(t, core.registered_aliases[name]) end } -setmetatable(minetest.registered_items, alias_metatable) -setmetatable(minetest.registered_nodes, alias_metatable) -setmetatable(minetest.registered_craftitems, alias_metatable) -setmetatable(minetest.registered_tools, alias_metatable) +setmetatable(core.registered_items, alias_metatable) +setmetatable(core.registered_nodes, alias_metatable) +setmetatable(core.registered_craftitems, alias_metatable) +setmetatable(core.registered_tools, alias_metatable) -- These item names may not be used because they would interfere -- with legacy itemstrings @@ -55,7 +55,7 @@ local function check_modname_prefix(name) return name:sub(2) else -- Modname prefix enforcement - local expected_prefix = minetest.get_current_modname() .. ":" + local expected_prefix = core.get_current_modname() .. ":" if name:sub(1, #expected_prefix) ~= expected_prefix then error("Name " .. name .. " does not follow naming conventions: " .. "\"modname:\" or \":\" prefix required") @@ -69,12 +69,12 @@ local function check_modname_prefix(name) end end -function minetest.register_abm(spec) - -- Add to minetest.registered_abms - minetest.registered_abms[#minetest.registered_abms+1] = spec +function core.register_abm(spec) + -- Add to core.registered_abms + core.registered_abms[#core.registered_abms+1] = spec end -function minetest.register_entity(name, prototype) +function core.register_entity(name, prototype) -- Check name if name == nil then error("Unable to register entity: Name is nil") @@ -84,11 +84,11 @@ function minetest.register_entity(name, prototype) prototype.name = name prototype.__index = prototype -- so that it can be used as a metatable - -- Add to minetest.registered_entities - minetest.registered_entities[name] = prototype + -- Add to core.registered_entities + core.registered_entities[name] = prototype end -function minetest.register_item(name, itemdef) +function core.register_item(name, itemdef) -- Check name if name == nil then error("Unable to register item: Name is nil") @@ -110,16 +110,16 @@ function minetest.register_item(name, itemdef) fixed = {-1/8, -1/2, -1/8, 1/8, 1/2, 1/8}, } end - setmetatable(itemdef, {__index = minetest.nodedef_default}) - minetest.registered_nodes[itemdef.name] = itemdef + setmetatable(itemdef, {__index = core.nodedef_default}) + core.registered_nodes[itemdef.name] = itemdef elseif itemdef.type == "craft" then - setmetatable(itemdef, {__index = minetest.craftitemdef_default}) - minetest.registered_craftitems[itemdef.name] = itemdef + setmetatable(itemdef, {__index = core.craftitemdef_default}) + core.registered_craftitems[itemdef.name] = itemdef elseif itemdef.type == "tool" then - setmetatable(itemdef, {__index = minetest.tooldef_default}) - minetest.registered_tools[itemdef.name] = itemdef + setmetatable(itemdef, {__index = core.tooldef_default}) + core.registered_tools[itemdef.name] = itemdef elseif itemdef.type == "none" then - setmetatable(itemdef, {__index = minetest.noneitemdef_default}) + setmetatable(itemdef, {__index = core.noneitemdef_default}) else error("Unable to register item: Type is invalid: " .. dump(itemdef)) end @@ -131,7 +131,7 @@ function minetest.register_item(name, itemdef) -- BEGIN Legacy stuff if itemdef.cookresult_itemstring ~= nil and itemdef.cookresult_itemstring ~= "" then - minetest.register_craft({ + core.register_craft({ type="cooking", output=itemdef.cookresult_itemstring, recipe=itemdef.name, @@ -139,7 +139,7 @@ function minetest.register_item(name, itemdef) }) end if itemdef.furnace_burntime ~= nil and itemdef.furnace_burntime >= 0 then - minetest.register_craft({ + core.register_craft({ type="fuel", recipe=itemdef.name, burntime=itemdef.furnace_burntime @@ -150,18 +150,18 @@ function minetest.register_item(name, itemdef) -- Disable all further modifications getmetatable(itemdef).__newindex = {} - --minetest.log("Registering item: " .. itemdef.name) - minetest.registered_items[itemdef.name] = itemdef - minetest.registered_aliases[itemdef.name] = nil + --core.log("Registering item: " .. itemdef.name) + core.registered_items[itemdef.name] = itemdef + core.registered_aliases[itemdef.name] = nil register_item_raw(itemdef) end -function minetest.register_node(name, nodedef) +function core.register_node(name, nodedef) nodedef.type = "node" - minetest.register_item(name, nodedef) + core.register_item(name, nodedef) end -function minetest.register_craftitem(name, craftitemdef) +function core.register_craftitem(name, craftitemdef) craftitemdef.type = "craft" -- BEGIN Legacy stuff @@ -170,10 +170,10 @@ function minetest.register_craftitem(name, craftitemdef) end -- END Legacy stuff - minetest.register_item(name, craftitemdef) + core.register_item(name, craftitemdef) end -function minetest.register_tool(name, tooldef) +function core.register_tool(name, tooldef) tooldef.type = "tool" tooldef.stack_max = 1 @@ -209,39 +209,39 @@ function minetest.register_tool(name, tooldef) end -- END Legacy stuff - minetest.register_item(name, tooldef) + core.register_item(name, tooldef) end -function minetest.register_alias(name, convert_to) +function core.register_alias(name, convert_to) if forbidden_item_names[name] then error("Unable to register alias: Name is forbidden: " .. name) end - if minetest.registered_items[name] ~= nil then - minetest.log("WARNING: Not registering alias, item with same name" .. + if core.registered_items[name] ~= nil then + core.log("WARNING: Not registering alias, item with same name" .. " is already defined: " .. name .. " -> " .. convert_to) else - --minetest.log("Registering alias: " .. name .. " -> " .. convert_to) - minetest.registered_aliases[name] = convert_to + --core.log("Registering alias: " .. name .. " -> " .. convert_to) + core.registered_aliases[name] = convert_to register_alias_raw(name, convert_to) end end -local register_biome_raw = minetest.register_biome -minetest.registered_biomes = {} -function minetest.register_biome(biome) - minetest.registered_biomes[biome.name] = biome +local register_biome_raw = core.register_biome +core.registered_biomes = {} +function core.register_biome(biome) + core.registered_biomes[biome.name] = biome register_biome_raw(biome) end -function minetest.on_craft(itemstack, player, old_craft_list, craft_inv) - for _, func in ipairs(minetest.registered_on_crafts) do +function core.on_craft(itemstack, player, old_craft_list, craft_inv) + for _, func in ipairs(core.registered_on_crafts) do itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack end return itemstack end -function minetest.craft_predict(itemstack, player, old_craft_list, craft_inv) - for _, func in ipairs(minetest.registered_craft_predicts) do +function core.craft_predict(itemstack, player, old_craft_list, craft_inv) + for _, func in ipairs(core.registered_craft_predicts) do itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack end return itemstack @@ -251,32 +251,32 @@ end -- created via itemstrings (e.g. /give) local name for name in pairs(forbidden_item_names) do - minetest.registered_aliases[name] = "" + core.registered_aliases[name] = "" register_alias_raw(name, "") end -- Deprecated: --- Aliases for minetest.register_alias (how ironic...) ---minetest.alias_node = minetest.register_alias ---minetest.alias_tool = minetest.register_alias ---minetest.alias_craftitem = minetest.register_alias +-- Aliases for core.register_alias (how ironic...) +--core.alias_node = core.register_alias +--core.alias_tool = core.register_alias +--core.alias_craftitem = core.register_alias -- -- Built-in node definitions. Also defined in C. -- -minetest.register_item(":unknown", { +core.register_item(":unknown", { type = "none", description = "Unknown Item", inventory_image = "unknown_item.png", - on_place = minetest.item_place, - on_drop = minetest.item_drop, + on_place = core.item_place, + on_drop = core.item_drop, groups = {not_in_creative_inventory=1}, diggable = true, }) -minetest.register_node(":air", { +core.register_node(":air", { description = "Air (you hacker you!)", inventory_image = "unknown_node.png", wield_image = "unknown_node.png", @@ -292,7 +292,7 @@ minetest.register_node(":air", { groups = {not_in_creative_inventory=1}, }) -minetest.register_node(":ignore", { +core.register_node(":ignore", { description = "Ignore (you hacker you!)", inventory_image = "unknown_node.png", wield_image = "unknown_node.png", @@ -309,20 +309,20 @@ minetest.register_node(":ignore", { }) -- The hand (bare definition) -minetest.register_item(":", { +core.register_item(":", { type = "none", groups = {not_in_creative_inventory=1}, }) -function minetest.override_item(name, redefinition) +function core.override_item(name, redefinition) if redefinition.name ~= nil then error("Attempt to redefine name of "..name.." to "..dump(redefinition.name), 2) end if redefinition.type ~= nil then error("Attempt to redefine type of "..name.." to "..dump(redefinition.type), 2) end - local item = minetest.registered_items[name] + local item = core.registered_items[name] if not item then error("Attempt to override non-existent item "..name, 2) end @@ -333,7 +333,7 @@ function minetest.override_item(name, redefinition) end -function minetest.run_callbacks(callbacks, mode, ...) +function core.run_callbacks(callbacks, mode, ...) assert(type(callbacks) == "table") local cb_len = #callbacks if cb_len == 0 then @@ -387,24 +387,24 @@ local function make_registration_reverse() return t, registerfunc end -minetest.registered_on_chat_messages, minetest.register_on_chat_message = make_registration() -minetest.registered_globalsteps, minetest.register_globalstep = make_registration() -minetest.registered_playerevents, minetest.register_playerevent = make_registration() -minetest.registered_on_mapgen_inits, minetest.register_on_mapgen_init = make_registration() -minetest.registered_on_shutdown, minetest.register_on_shutdown = make_registration() -minetest.registered_on_punchnodes, minetest.register_on_punchnode = make_registration() -minetest.registered_on_placenodes, minetest.register_on_placenode = make_registration() -minetest.registered_on_dignodes, minetest.register_on_dignode = make_registration() -minetest.registered_on_generateds, minetest.register_on_generated = make_registration() -minetest.registered_on_newplayers, minetest.register_on_newplayer = make_registration() -minetest.registered_on_dieplayers, minetest.register_on_dieplayer = make_registration() -minetest.registered_on_respawnplayers, minetest.register_on_respawnplayer = make_registration() -minetest.registered_on_prejoinplayers, minetest.register_on_prejoinplayer = make_registration() -minetest.registered_on_joinplayers, minetest.register_on_joinplayer = make_registration() -minetest.registered_on_leaveplayers, minetest.register_on_leaveplayer = make_registration() -minetest.registered_on_player_receive_fields, minetest.register_on_player_receive_fields = make_registration_reverse() -minetest.registered_on_cheats, minetest.register_on_cheat = make_registration() -minetest.registered_on_crafts, minetest.register_on_craft = make_registration() -minetest.registered_craft_predicts, minetest.register_craft_predict = make_registration() -minetest.registered_on_protection_violation, minetest.register_on_protection_violation = make_registration() +core.registered_on_chat_messages, core.register_on_chat_message = make_registration() +core.registered_globalsteps, core.register_globalstep = make_registration() +core.registered_playerevents, core.register_playerevent = make_registration() +core.registered_on_mapgen_inits, core.register_on_mapgen_init = make_registration() +core.registered_on_shutdown, core.register_on_shutdown = make_registration() +core.registered_on_punchnodes, core.register_on_punchnode = make_registration() +core.registered_on_placenodes, core.register_on_placenode = make_registration() +core.registered_on_dignodes, core.register_on_dignode = make_registration() +core.registered_on_generateds, core.register_on_generated = make_registration() +core.registered_on_newplayers, core.register_on_newplayer = make_registration() +core.registered_on_dieplayers, core.register_on_dieplayer = make_registration() +core.registered_on_respawnplayers, core.register_on_respawnplayer = make_registration() +core.registered_on_prejoinplayers, core.register_on_prejoinplayer = make_registration() +core.registered_on_joinplayers, core.register_on_joinplayer = make_registration() +core.registered_on_leaveplayers, core.register_on_leaveplayer = make_registration() +core.registered_on_player_receive_fields, core.register_on_player_receive_fields = make_registration_reverse() +core.registered_on_cheats, core.register_on_cheat = make_registration() +core.registered_on_crafts, core.register_on_craft = make_registration() +core.registered_craft_predicts, core.register_craft_predict = make_registration() +core.registered_on_protection_violation, core.register_on_protection_violation = make_registration() diff --git a/builtin/game/statbars.lua b/builtin/game/statbars.lua index ca656a974..9e5699314 100644 --- a/builtin/game/statbars.lua +++ b/builtin/game/statbars.lua @@ -118,7 +118,7 @@ local function player_event_handler(player,eventname) return false end -function minetest.hud_replace_builtin(name, definition) +function core.hud_replace_builtin(name, definition) if definition == nil or type(definition) ~= "table" or @@ -130,7 +130,7 @@ function minetest.hud_replace_builtin(name, definition) health_bar_definition = definition for name,ids in pairs(hud_ids) do - local player = minetest.get_player_by_name(name) + local player = core.get_player_by_name(name) if player and hud_ids[name].id_healthbar then player:hud_remove(hud_ids[name].id_healthbar) initialize_builtin_statbars(player) @@ -143,7 +143,7 @@ function minetest.hud_replace_builtin(name, definition) breath_bar_definition = definition for name,ids in pairs(hud_ids) do - local player = minetest.get_player_by_name(name) + local player = core.get_player_by_name(name) if player and hud_ids[name].id_breathbar then player:hud_remove(hud_ids[name].id_breathbar) initialize_builtin_statbars(player) @@ -155,6 +155,6 @@ function minetest.hud_replace_builtin(name, definition) return false end -minetest.register_on_joinplayer(initialize_builtin_statbars) -minetest.register_on_leaveplayer(cleanup_builtin_statbars) -minetest.register_playerevent(player_event_handler) +core.register_on_joinplayer(initialize_builtin_statbars) +core.register_on_leaveplayer(cleanup_builtin_statbars) +core.register_playerevent(player_event_handler) diff --git a/builtin/game/static_spawn.lua b/builtin/game/static_spawn.lua index e8c107d86..492ab6ca6 100644 --- a/builtin/game/static_spawn.lua +++ b/builtin/game/static_spawn.lua @@ -1,10 +1,10 @@ -- Minetest: builtin/static_spawn.lua local function warn_invalid_static_spawnpoint() - if minetest.setting_get("static_spawnpoint") and - not minetest.setting_get_pos("static_spawnpoint") then - minetest.log('error', "The static_spawnpoint setting is invalid: \"".. - minetest.setting_get("static_spawnpoint").."\"") + if core.setting_get("static_spawnpoint") and + not core.setting_get_pos("static_spawnpoint") then + core.log('error', "The static_spawnpoint setting is invalid: \"".. + core.setting_get("static_spawnpoint").."\"") end end @@ -12,22 +12,22 @@ warn_invalid_static_spawnpoint() local function put_player_in_spawn(obj) warn_invalid_static_spawnpoint() - local static_spawnpoint = minetest.setting_get_pos("static_spawnpoint") + local static_spawnpoint = core.setting_get_pos("static_spawnpoint") if not static_spawnpoint then return false end - minetest.log('action', "Moving "..obj:get_player_name().. + core.log('action', "Moving "..obj:get_player_name().. " to static spawnpoint at ".. - minetest.pos_to_string(static_spawnpoint)) + core.pos_to_string(static_spawnpoint)) obj:setpos(static_spawnpoint) return true end -minetest.register_on_newplayer(function(obj) +core.register_on_newplayer(function(obj) put_player_in_spawn(obj) end) -minetest.register_on_respawnplayer(function(obj) +core.register_on_respawnplayer(function(obj) return put_player_in_spawn(obj) end) diff --git a/builtin/init.lua b/builtin/init.lua index 9969111b8..4f55e8034 100644 --- a/builtin/init.lua +++ b/builtin/init.lua @@ -5,13 +5,11 @@ -- before loading and running any mods. -- -local core = minetest or engine -minetest = core - -- Initialize some very basic things print = core.debug math.randomseed(os.time()) os.setlocale("C", "numeric") +minetest = core -- Load other files local scriptdir = core.get_builtin_path()..DIR_DELIM diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index d78a668c5..58e9ab949 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -1,6 +1,7 @@ -local menupath = engine.get_mainmenu_path()..DIR_DELIM -local commonpath = engine.get_builtin_path()..DIR_DELIM.."common"..DIR_DELIM +engine = core +local menupath = core.get_mainmenu_path()..DIR_DELIM +local commonpath = core.get_builtin_path()..DIR_DELIM.."common"..DIR_DELIM dofile(menupath.."filterlist.lua") dofile(menupath.."modmgr.lua") @@ -217,7 +218,7 @@ function menu.asyncOnlineFavourites() menu.favorites = {} engine.handle_async( function(param) - return engine.get_favorites("online") + --return core.get_favorites("online") end, nil, function(result) diff --git a/builtin/mainmenu/modmgr.lua b/builtin/mainmenu/modmgr.lua index eeb65add1..baf61d2a5 100644 --- a/builtin/mainmenu/modmgr.lua +++ b/builtin/mainmenu/modmgr.lua @@ -193,16 +193,9 @@ function modmgr.identify_modname(modpath,filename) while line~= nil do local modname = nil - if line:find("minetest.register_tool") then - modname = modmgr.parse_register_line(line) - end - - if line:find("minetest.register_craftitem") then - modname = modmgr.parse_register_line(line) - end - - - if line:find("minetest.register_node") then + if line:find("register_tool") or + line:find("register_craftitem") or + line:find("register_node") then modname = modmgr.parse_register_line(line) end @@ -225,7 +218,6 @@ end -------------------------------------------------------------------------------- function modmgr.tab() - if modmgr.global_mods == nil then modmgr.refresh_globals() end diff --git a/doc/menu_lua_api.txt b/doc/menu_lua_api.txt index 321f74a8c..109aededa 100644 --- a/doc/menu_lua_api.txt +++ b/doc/menu_lua_api.txt @@ -3,7 +3,7 @@ Minetest Lua Mainmenu API Reference 0.4.9 Introduction ------------- -The main menu is defined as a formspec by Lua in builtin/mainmenu.lua +The main menu is defined as a formspec by Lua in builtin/mainmenu/ Description of formspec language to show your menu is in lua_api.txt Callbacks @@ -83,7 +83,7 @@ engine.download_file(url,target) (possible in async calls) ^ target to store to ^ returns true/false engine.get_version() (possible in async calls) -^ returns current minetest version +^ returns current core version engine.sound_play(spec, looped) -> handle ^ spec = SimpleSoundSpec (see lua-api.txt) ^ looped = bool @@ -191,14 +191,14 @@ fgettext(string, ...) -> string ^ call engine.gettext(string), replace "$1"..."$9" with the given ^ extra arguments, call engine.formspec_escape and return the result engine.parse_json(string[, nullvalue]) -> something (possible in async calls) -^ see minetest.parse_json (lua_api.txt) +^ see core.parse_json (lua_api.txt) dump(obj, dumped={}) ^ Return object serialized as a string string:split(separator) ^ eg. string:split("a,b", ",") == {"a","b"} string:trim() ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar" -minetest.is_yes(arg) (possible in async calls) +core.is_yes(arg) (possible in async calls) ^ returns whether arg can be interpreted as yes Async: diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 2898d28ae..2f749043e 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -955,14 +955,14 @@ std::vector read_items(lua_State *L, int index, Server *srv) /******************************************************************************/ void luaentity_get(lua_State *L, u16 id) { - // Get minetest.luaentities[i] - lua_getglobal(L, "minetest"); + // Get luaentities[i] + lua_getglobal(L, "core"); lua_getfield(L, -1, "luaentities"); luaL_checktype(L, -1, LUA_TTABLE); lua_pushnumber(L, id); lua_gettable(L, -2); - lua_remove(L, -2); // luaentities - lua_remove(L, -2); // minetest + lua_remove(L, -2); // Remove luaentities + lua_remove(L, -2); // Remove core } /******************************************************************************/ diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp index 4c6604f65..4c098f8d5 100644 --- a/src/script/common/c_internal.cpp +++ b/src/script/common/c_internal.cpp @@ -92,8 +92,8 @@ void script_run_callbacks(lua_State *L, int nargs, RunCallbacksMode mode) int errorhandler = lua_gettop(L) - nargs - 1; lua_insert(L, errorhandler); - // Insert minetest.run_callbacks between error handler and table - lua_getglobal(L, "minetest"); + // Insert run_callbacks between error handler and table + lua_getglobal(L, "core"); lua_getfield(L, -1, "run_callbacks"); lua_remove(L, -2); lua_insert(L, errorhandler + 1); diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index 64260fb3a..0b19572c2 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -146,7 +146,7 @@ void AsyncEngine::putJobResult(LuaJobInfo result) /******************************************************************************/ void AsyncEngine::step(lua_State *L, int errorhandler) { - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); resultQueueMutex.Lock(); while (!resultQueue.empty()) { LuaJobInfo jobDone = resultQueue.front(); @@ -169,7 +169,7 @@ void AsyncEngine::step(lua_State *L, int errorhandler) } } resultQueueMutex.Unlock(); - lua_pop(L, 1); // Pop engine + lua_pop(L, 1); // Pop core } /******************************************************************************/ @@ -223,17 +223,10 @@ AsyncWorkerThread::AsyncWorkerThread(AsyncEngine* jobDispatcher, { lua_State *L = getStack(); - luaL_openlibs(L); - // Prepare job lua environment - lua_newtable(L); - lua_setglobal(L, "engine"); - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); int top = lua_gettop(L); - lua_pushstring(L, DIR_DELIM); - lua_setglobal(L, "DIR_DELIM"); - // Push builtin initialization type lua_pushstring(L, "async"); lua_setglobal(L, "INIT"); @@ -278,9 +271,9 @@ void* AsyncWorkerThread::Thread() continue; } - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); if (lua_isnil(L, -1)) { - errorstream << "Unable to find engine within async environment!"; + errorstream << "Unable to find core within async environment!"; abort(); } @@ -310,7 +303,7 @@ void* AsyncWorkerThread::Thread() toProcess.serializedResult = std::string(retval, length); } - // Pop engine, job_processor, and retval + // Pop core, job_processor, and retval lua_pop(L, 3); // Put job result diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 1a172fd31..d27506fbe 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_object.h" #include "serverobject.h" #include "debug.h" +#include "filesys.h" #include "log.h" #include "mods.h" #include "util/string.h" @@ -48,13 +49,13 @@ public: { // Store current modname in registry lua_pushstring(L, modname.c_str()); - lua_setfield(L, LUA_REGISTRYINDEX, "minetest_current_modname"); + lua_setfield(L, LUA_REGISTRYINDEX, "current_modname"); } ~ModNameStorer() { // Clear current modname in registry lua_pushnil(L); - lua_setfield(L, LUA_REGISTRYINDEX, "minetest_current_modname"); + lua_setfield(L, LUA_REGISTRYINDEX, "current_modname"); } }; @@ -72,6 +73,8 @@ ScriptApiBase::ScriptApiBase() m_luastack = luaL_newstate(); assert(m_luastack); + luaL_openlibs(m_luastack); + // Add and save an error handler lua_pushcfunction(m_luastack, script_error_handler); m_errorhandler = lua_gettop(m_luastack); @@ -88,6 +91,13 @@ ScriptApiBase::ScriptApiBase() lua_pop(m_luastack, 1); #endif + // Add basic globals + lua_newtable(m_luastack); + lua_setglobal(m_luastack, "core"); + + lua_pushstring(m_luastack, DIR_DELIM); + lua_setglobal(m_luastack, "DIR_DELIM"); + m_server = NULL; m_environment = NULL; m_guiengine = NULL; @@ -191,8 +201,8 @@ void ScriptApiBase::addObjectReference(ServerActiveObject *cobj) ObjectRef::create(L, cobj); // Puts ObjectRef (as userdata) on stack int object = lua_gettop(L); - // Get minetest.object_refs table - lua_getglobal(L, "minetest"); + // Get core.object_refs table + lua_getglobal(L, "core"); lua_getfield(L, -1, "object_refs"); luaL_checktype(L, -1, LUA_TTABLE); int objectstable = lua_gettop(L); @@ -208,8 +218,8 @@ void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj) SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_rm_object_reference: id="<getId()< SCRIPTAPI_PRECHECKHEADER // Get handler function - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "button_handler"); - lua_remove(L, -2); // Remove engine + lua_remove(L, -2); // Remove core if (lua_isnil(L, -1)) { lua_pop(L, 1); // Pop button handler return; diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index d357689f2..d7375082a 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -25,8 +25,8 @@ void ScriptApiPlayer::on_newplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_newplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_newplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_newplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -37,8 +37,8 @@ void ScriptApiPlayer::on_dieplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_dieplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_dieplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_dieplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -49,8 +49,8 @@ bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_respawnplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_respawnplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_respawnplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -63,8 +63,8 @@ bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::st { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_prejoinplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_prejoinplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_prejoinplayers"); lua_pushstring(L, name.c_str()); lua_pushstring(L, ip.c_str()); @@ -80,8 +80,8 @@ void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_joinplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_joinplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_joinplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -92,8 +92,8 @@ void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_leaveplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_leaveplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_leaveplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -105,8 +105,8 @@ void ScriptApiPlayer::on_cheat(ServerActiveObject *player, { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_cheats - lua_getglobal(L, "minetest"); + // Get core.registered_on_cheats + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_cheats"); // Call callbacks objectrefGetOrCreate(player); @@ -122,8 +122,8 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player, { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_chat_messages - lua_getglobal(L, "minetest"); + // Get core.registered_on_chat_messages + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_player_receive_fields"); // Call callbacks // param 1 diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp index 7d21f968b..21fe164aa 100644 --- a/src/script/cpp_api/s_server.cpp +++ b/src/script/cpp_api/s_server.cpp @@ -62,13 +62,13 @@ void ScriptApiServer::getAuthHandler() { lua_State *L = getStack(); - lua_getglobal(L, "minetest"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_auth_handler"); if (lua_isnil(L, -1)){ lua_pop(L, 1); lua_getfield(L, -1, "builtin_auth_handler"); } - lua_remove(L, -2); // Remove minetest + lua_remove(L, -2); // Remove core if (lua_type(L, -1) != LUA_TTABLE) throw LuaError("Authentication handler table not valid"); } @@ -130,8 +130,8 @@ bool ScriptApiServer::on_chat_message(const std::string &name, { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_chat_messages - lua_getglobal(L, "minetest"); + // Get core.registered_on_chat_messages + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_chat_messages"); // Call callbacks lua_pushstring(L, name.c_str()); @@ -146,7 +146,7 @@ void ScriptApiServer::on_shutdown() SCRIPTAPI_PRECHECKHEADER // Get registered shutdown hooks - lua_getglobal(L, "minetest"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_shutdown"); // Call callbacks script_run_callbacks(L, 0, RUN_CALLBACKS_MODE_FIRST); diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 37fa167e6..42bfc4beb 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -56,24 +56,24 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, lua_pushcfunction(L, script_error_handler); int errorhandler = lua_gettop(L); - // Get minetest.registered_abms - lua_getglobal(L, "minetest"); + // Get registered_abms + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_abms"); luaL_checktype(L, -1, LUA_TTABLE); - lua_remove(L, -2); // Remove "minetest" + lua_remove(L, -2); // Remove core - // Get minetest.registered_abms[m_id] + // Get registered_abms[m_id] lua_pushnumber(L, m_id); lua_gettable(L, -2); if(lua_isnil(L, -1)) assert(0); - lua_remove(L, -2); // Remove "registered_abms" + lua_remove(L, -2); // Remove registered_abms // Call action luaL_checktype(L, -1, LUA_TTABLE); lua_getfield(L, -1, "action"); luaL_checktype(L, -1, LUA_TFUNCTION); - lua_remove(L, -2); // Remove "registered_abms[m_id]" + lua_remove(L, -2); // Remove registered_abms[m_id] push_v3s16(L, p); pushnode(L, n, env->getGameDef()->ndef()); lua_pushnumber(L, active_object_count); @@ -85,7 +85,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, // Exported functions -// minetest.set_node(pos, node) +// set_node(pos, node) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_set_node(lua_State *L) { @@ -106,7 +106,7 @@ int ModApiEnvMod::l_add_node(lua_State *L) return l_set_node(L); } -// minetest.remove_node(pos) +// remove_node(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_remove_node(lua_State *L) { @@ -120,7 +120,7 @@ int ModApiEnvMod::l_remove_node(lua_State *L) return 1; } -// minetest.swap_node(pos, node) +// swap_node(pos, node) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_swap_node(lua_State *L) { @@ -136,7 +136,7 @@ int ModApiEnvMod::l_swap_node(lua_State *L) return 1; } -// minetest.get_node(pos) +// get_node(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node(lua_State *L) { @@ -151,7 +151,7 @@ int ModApiEnvMod::l_get_node(lua_State *L) return 1; } -// minetest.get_node_or_nil(pos) +// get_node_or_nil(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node_or_nil(lua_State *L) { @@ -172,7 +172,7 @@ int ModApiEnvMod::l_get_node_or_nil(lua_State *L) } } -// minetest.get_node_light(pos, timeofday) +// get_node_light(pos, timeofday) // pos = {x=num, y=num, z=num} // timeofday: nil = current time, 0 = night, 0.5 = day int ModApiEnvMod::l_get_node_light(lua_State *L) @@ -198,7 +198,7 @@ int ModApiEnvMod::l_get_node_light(lua_State *L) } } -// minetest.place_node(pos, node) +// place_node(pos, node) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_place_node(lua_State *L) { @@ -232,7 +232,7 @@ int ModApiEnvMod::l_place_node(lua_State *L) return 1; } -// minetest.dig_node(pos) +// dig_node(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_dig_node(lua_State *L) { @@ -255,7 +255,7 @@ int ModApiEnvMod::l_dig_node(lua_State *L) return 1; } -// minetest.punch_node(pos) +// punch_node(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_punch_node(lua_State *L) { @@ -278,7 +278,7 @@ int ModApiEnvMod::l_punch_node(lua_State *L) return 1; } -// minetest.get_node_max_level(pos) +// get_node_max_level(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node_max_level(lua_State *L) { @@ -290,7 +290,7 @@ int ModApiEnvMod::l_get_node_max_level(lua_State *L) return 1; } -// minetest.get_node_level(pos) +// get_node_level(pos) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node_level(lua_State *L) { @@ -302,7 +302,7 @@ int ModApiEnvMod::l_get_node_level(lua_State *L) return 1; } -// minetest.set_node_level(pos, level) +// set_node_level(pos, level) // pos = {x=num, y=num, z=num} // level: 0..63 int ModApiEnvMod::l_set_node_level(lua_State *L) @@ -319,7 +319,7 @@ int ModApiEnvMod::l_set_node_level(lua_State *L) return 1; } -// minetest.add_node_level(pos, level) +// add_node_level(pos, level) // pos = {x=num, y=num, z=num} // level: 0..63 int ModApiEnvMod::l_add_node_level(lua_State *L) @@ -337,7 +337,7 @@ int ModApiEnvMod::l_add_node_level(lua_State *L) } -// minetest.get_meta(pos) +// get_meta(pos) int ModApiEnvMod::l_get_meta(lua_State *L) { GET_ENV_PTR; @@ -348,7 +348,7 @@ int ModApiEnvMod::l_get_meta(lua_State *L) return 1; } -// minetest.get_node_timer(pos) +// get_node_timer(pos) int ModApiEnvMod::l_get_node_timer(lua_State *L) { GET_ENV_PTR; @@ -359,7 +359,7 @@ int ModApiEnvMod::l_get_node_timer(lua_State *L) return 1; } -// minetest.add_entity(pos, entityname) -> ObjectRef or nil +// add_entity(pos, entityname) -> ObjectRef or nil // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_add_entity(lua_State *L) { @@ -380,7 +380,7 @@ int ModApiEnvMod::l_add_entity(lua_State *L) return 1; } -// minetest.add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil +// add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_add_item(lua_State *L) { @@ -396,10 +396,10 @@ int ModApiEnvMod::l_add_item(lua_State *L) lua_pushcfunction(L, script_error_handler); int errorhandler = lua_gettop(L); - // Use minetest.spawn_item to spawn a __builtin:item - lua_getglobal(L, "minetest"); + // Use spawn_item to spawn a __builtin:item + lua_getglobal(L, "core"); lua_getfield(L, -1, "spawn_item"); - lua_remove(L, -2); // Remove minetest + lua_remove(L, -2); // Remove core if(lua_isnil(L, -1)) return 0; lua_pushvalue(L, 1); @@ -423,7 +423,7 @@ int ModApiEnvMod::l_add_item(lua_State *L) return 1;*/ } -// minetest.get_player_by_name(name) +// get_player_by_name(name) int ModApiEnvMod::l_get_player_by_name(lua_State *L) { GET_ENV_PTR; @@ -445,7 +445,7 @@ int ModApiEnvMod::l_get_player_by_name(lua_State *L) return 1; } -// minetest.get_objects_inside_radius(pos, radius) +// get_objects_inside_radius(pos, radius) int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L) { GET_ENV_PTR; @@ -466,7 +466,7 @@ int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L) return 1; } -// minetest.set_timeofday(val) +// set_timeofday(val) // val = 0...1 int ModApiEnvMod::l_set_timeofday(lua_State *L) { @@ -484,7 +484,7 @@ int ModApiEnvMod::l_set_timeofday(lua_State *L) return 0; } -// minetest.get_timeofday() -> 0...1 +// get_timeofday() -> 0...1 int ModApiEnvMod::l_get_timeofday(lua_State *L) { GET_ENV_PTR; @@ -496,7 +496,7 @@ int ModApiEnvMod::l_get_timeofday(lua_State *L) return 1; } -// minetest.get_gametime() +// get_gametime() int ModApiEnvMod::l_get_gametime(lua_State *L) { GET_ENV_PTR; @@ -507,7 +507,7 @@ int ModApiEnvMod::l_get_gametime(lua_State *L) } -// minetest.find_node_near(pos, radius, nodenames) -> pos or nil +// find_node_near(pos, radius, nodenames) -> pos or nil // nodenames: eg. {"ignore", "group:tree"} or "default:dirt" int ModApiEnvMod::l_find_node_near(lua_State *L) { @@ -547,7 +547,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) return 0; } -// minetest.find_nodes_in_area(minp, maxp, nodenames) -> list of positions +// find_nodes_in_area(minp, maxp, nodenames) -> list of positions // nodenames: eg. {"ignore", "group:tree"} or "default:dirt" int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) { @@ -586,7 +586,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) return 1; } -// minetest.get_perlin(seeddiff, octaves, persistence, scale) +// get_perlin(seeddiff, octaves, persistence, scale) // returns world-specific PerlinNoise int ModApiEnvMod::l_get_perlin(lua_State *L) { @@ -604,7 +604,7 @@ int ModApiEnvMod::l_get_perlin(lua_State *L) return 1; } -// minetest.get_perlin_map(noiseparams, size) +// get_perlin_map(noiseparams, size) // returns world-specific PerlinNoiseMap int ModApiEnvMod::l_get_perlin_map(lua_State *L) { @@ -623,7 +623,7 @@ int ModApiEnvMod::l_get_perlin_map(lua_State *L) return 1; } -// minetest.get_voxel_manip() +// get_voxel_manip() // returns voxel manipulator int ModApiEnvMod::l_get_voxel_manip(lua_State *L) { @@ -638,7 +638,7 @@ int ModApiEnvMod::l_get_voxel_manip(lua_State *L) return 1; } -// minetest.clear_objects() +// clear_objects() // clear all objects in the environment int ModApiEnvMod::l_clear_objects(lua_State *L) { @@ -648,7 +648,7 @@ int ModApiEnvMod::l_clear_objects(lua_State *L) return 0; } -// minetest.line_of_sight(pos1, pos2, stepsize) -> true/false, pos +// line_of_sight(pos1, pos2, stepsize) -> true/false, pos int ModApiEnvMod::l_line_of_sight(lua_State *L) { float stepsize = 1.0; @@ -673,7 +673,7 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) { return 1; } -// minetest.find_path(pos1, pos2, searchdistance, +// find_path(pos1, pos2, searchdistance, // max_jump, max_drop, algorithm) -> table containing path int ModApiEnvMod::l_find_path(lua_State *L) { @@ -716,7 +716,7 @@ int ModApiEnvMod::l_find_path(lua_State *L) return 0; } -// minetest.spawn_tree(pos, treedef) +// spawn_tree(pos, treedef) int ModApiEnvMod::l_spawn_tree(lua_State *L) { GET_ENV_PTR; @@ -765,7 +765,7 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L) return 1; } -// minetest.transforming_liquid_add(pos) +// transforming_liquid_add(pos) int ModApiEnvMod::l_transforming_liquid_add(lua_State *L) { GET_ENV_PTR; @@ -775,7 +775,7 @@ int ModApiEnvMod::l_transforming_liquid_add(lua_State *L) return 1; } -// minetest.forceload_block(blockpos) +// forceload_block(blockpos) // blockpos = {x=num, y=num, z=num} int ModApiEnvMod::l_forceload_block(lua_State *L) { @@ -786,7 +786,7 @@ int ModApiEnvMod::l_forceload_block(lua_State *L) return 0; } -// minetest.forceload_free_block(blockpos) +// forceload_free_block(blockpos) // blockpos = {x=num, y=num, z=num} int ModApiEnvMod::l_forceload_free_block(lua_State *L) { diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index 8bf599b0c..420866d5d 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -25,134 +25,134 @@ with this program; if not, write to the Free Software Foundation, Inc., class ModApiEnvMod : public ModApiBase { private: - // minetest.set_node(pos, node) + // set_node(pos, node) // pos = {x=num, y=num, z=num} static int l_set_node(lua_State *L); static int l_add_node(lua_State *L); - // minetest.remove_node(pos) + // remove_node(pos) // pos = {x=num, y=num, z=num} static int l_remove_node(lua_State *L); - // minetest.swap_node(pos, node) + // swap_node(pos, node) // pos = {x=num, y=num, z=num} static int l_swap_node(lua_State *L); - // minetest.get_node(pos) + // get_node(pos) // pos = {x=num, y=num, z=num} static int l_get_node(lua_State *L); - // minetest.get_node_or_nil(pos) + // get_node_or_nil(pos) // pos = {x=num, y=num, z=num} static int l_get_node_or_nil(lua_State *L); - // minetest.get_node_light(pos, timeofday) + // get_node_light(pos, timeofday) // pos = {x=num, y=num, z=num} // timeofday: nil = current time, 0 = night, 0.5 = day static int l_get_node_light(lua_State *L); - // minetest.place_node(pos, node) + // place_node(pos, node) // pos = {x=num, y=num, z=num} static int l_place_node(lua_State *L); - // minetest.dig_node(pos) + // dig_node(pos) // pos = {x=num, y=num, z=num} static int l_dig_node(lua_State *L); - // minetest.punch_node(pos) + // punch_node(pos) // pos = {x=num, y=num, z=num} static int l_punch_node(lua_State *L); - // minetest.get_node_max_level(pos) + // get_node_max_level(pos) // pos = {x=num, y=num, z=num} static int l_get_node_max_level(lua_State *L); - // minetest.get_node_level(pos) + // get_node_level(pos) // pos = {x=num, y=num, z=num} static int l_get_node_level(lua_State *L); - // minetest.set_node_level(pos) + // set_node_level(pos) // pos = {x=num, y=num, z=num} static int l_set_node_level(lua_State *L); - // minetest.add_node_level(pos) + // add_node_level(pos) // pos = {x=num, y=num, z=num} static int l_add_node_level(lua_State *L); - // minetest.get_meta(pos) + // get_meta(pos) static int l_get_meta(lua_State *L); - // minetest.get_node_timer(pos) + // get_node_timer(pos) static int l_get_node_timer(lua_State *L); - // minetest.add_entity(pos, entityname) -> ObjectRef or nil + // add_entity(pos, entityname) -> ObjectRef or nil // pos = {x=num, y=num, z=num} static int l_add_entity(lua_State *L); - // minetest.add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil + // add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil // pos = {x=num, y=num, z=num} static int l_add_item(lua_State *L); - // minetest.get_player_by_name(name) + // get_player_by_name(name) static int l_get_player_by_name(lua_State *L); - // minetest.get_objects_inside_radius(pos, radius) + // get_objects_inside_radius(pos, radius) static int l_get_objects_inside_radius(lua_State *L); - // minetest.set_timeofday(val) + // set_timeofday(val) // val = 0...1 static int l_set_timeofday(lua_State *L); - // minetest.get_timeofday() -> 0...1 + // get_timeofday() -> 0...1 static int l_get_timeofday(lua_State *L); - // minetest.get_gametime() + // get_gametime() static int l_get_gametime(lua_State *L); - // minetest.find_node_near(pos, radius, nodenames) -> pos or nil + // find_node_near(pos, radius, nodenames) -> pos or nil // nodenames: eg. {"ignore", "group:tree"} or "default:dirt" static int l_find_node_near(lua_State *L); - // minetest.find_nodes_in_area(minp, maxp, nodenames) -> list of positions + // find_nodes_in_area(minp, maxp, nodenames) -> list of positions // nodenames: eg. {"ignore", "group:tree"} or "default:dirt" static int l_find_nodes_in_area(lua_State *L); - // minetest.get_perlin(seeddiff, octaves, persistence, scale) + // get_perlin(seeddiff, octaves, persistence, scale) // returns world-specific PerlinNoise static int l_get_perlin(lua_State *L); - // minetest.get_perlin_map(noiseparams, size) + // get_perlin_map(noiseparams, size) // returns world-specific PerlinNoiseMap static int l_get_perlin_map(lua_State *L); - // minetest.get_voxel_manip() + // get_voxel_manip() // returns world-specific voxel manipulator static int l_get_voxel_manip(lua_State *L); - // minetest.clear_objects() + // clear_objects() // clear all objects in the environment static int l_clear_objects(lua_State *L); - // minetest.spawn_tree(pos, treedef) + // spawn_tree(pos, treedef) static int l_spawn_tree(lua_State *L); - // minetest.line_of_sight(pos1, pos2, stepsize) -> true/false + // line_of_sight(pos1, pos2, stepsize) -> true/false static int l_line_of_sight(lua_State *L); - // minetest.find_path(pos1, pos2, searchdistance, + // find_path(pos1, pos2, searchdistance, // max_jump, max_drop, algorithm) -> table containing path static int l_find_path(lua_State *L); - // minetest.transforming_liquid_add(pos) + // transforming_liquid_add(pos) static int l_transforming_liquid_add(lua_State *L); - // minetest.forceload_block(blockpos) + // forceload_block(blockpos) // forceloads a block static int l_forceload_block(lua_State *L); - // minetest.forceload_free_block(blockpos) + // forceload_free_block(blockpos) // stops forceloading a position static int l_forceload_free_block(lua_State *L); diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index aef011da3..a45ae5168 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -361,7 +361,7 @@ int InvRef::l_remove_item(lua_State *L) return 1; } -// get_location() -> location (like minetest.get_inventory(location)) +// get_location() -> location (like get_inventory(location)) int InvRef::l_get_location(lua_State *L) { NO_MAP_LOCK_REQUIRED; diff --git a/src/script/lua_api/l_inventory.h b/src/script/lua_api/l_inventory.h index 03b241034..2d4b29d0c 100644 --- a/src/script/lua_api/l_inventory.h +++ b/src/script/lua_api/l_inventory.h @@ -101,7 +101,7 @@ private: // Returns the items that were actually removed static int l_remove_item(lua_State *L); - // get_location() -> location (like minetest.get_inventory(location)) + // get_location() -> location (like get_inventory(location)) static int l_get_location(lua_State *L); public: diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index 094d0bb25..bc6a8ecde 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -234,7 +234,7 @@ int LuaItemStack::l_is_known(lua_State *L) } // get_definition(self) -> table -// Returns the item definition table from minetest.registered_items, +// Returns the item definition table from registered_items, // or a fallback one (name="unknown") int LuaItemStack::l_get_definition(lua_State *L) { @@ -242,8 +242,8 @@ int LuaItemStack::l_get_definition(lua_State *L) LuaItemStack *o = checkobject(L, 1); ItemStack &item = o->m_stack; - // Get minetest.registered_items[name] - lua_getglobal(L, "minetest"); + // Get registered_items[name] + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_items"); luaL_checktype(L, -1, LUA_TTABLE); lua_getfield(L, -1, item.name.c_str()); diff --git a/src/script/lua_api/l_item.h b/src/script/lua_api/l_item.h index 7f5a1130d..0f9e4ba9b 100644 --- a/src/script/lua_api/l_item.h +++ b/src/script/lua_api/l_item.h @@ -85,7 +85,7 @@ private: static int l_is_known(lua_State *L); // get_definition(self) -> table - // Returns the item definition table from minetest.registered_items, + // Returns the item definition table from core.registered_items, // or a fallback one (name="unknown") static int l_get_definition(lua_State *L); diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 9fbb46ee1..287faade9 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -78,7 +78,7 @@ struct EnumString ModApiMapgen::es_Rotation[] = }; -// minetest.get_mapgen_object(objectname) +// get_mapgen_object(objectname) // returns the requested object used during map generation int ModApiMapgen::l_get_mapgen_object(lua_State *L) { @@ -181,7 +181,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) return 0; } -// minetest.set_mapgen_params(params) +// set_mapgen_params(params) // set mapgen parameters int ModApiMapgen::l_set_mapgen_params(lua_State *L) { @@ -225,7 +225,7 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L) return 0; } -// minetest.set_noiseparam_defaults({np1={noise params}, ...}) +// set_noiseparam_defaults({np1={noise params}, ...}) // set default values for noise parameters if not present in global settings int ModApiMapgen::l_set_noiseparam_defaults(lua_State *L) { diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h index 8624f9775..8ffe32893 100644 --- a/src/script/lua_api/l_mapgen.h +++ b/src/script/lua_api/l_mapgen.h @@ -24,15 +24,15 @@ with this program; if not, write to the Free Software Foundation, Inc., class ModApiMapgen : public ModApiBase { private: - // minetest.get_mapgen_object(objectname) + // get_mapgen_object(objectname) // returns the requested object used during map generation static int l_get_mapgen_object(lua_State *L); - // minetest.set_mapgen_params(params) + // set_mapgen_params(params) // set mapgen parameters static int l_set_mapgen_params(lua_State *L); - // minetest.set_noiseparam_defaults({np1={noise params}, ...}) + // set_noiseparam_defaults({np1={noise params}, ...}) static int l_set_noiseparam_defaults(lua_State *L); // set_gen_notify(flagstring) diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 7770a5ff4..76fe439eb 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -341,7 +341,7 @@ int ModApiServer::l_show_formspec(lua_State *L) int ModApiServer::l_get_current_modname(lua_State *L) { NO_MAP_LOCK_REQUIRED; - lua_getfield(L, LUA_REGISTRYINDEX, "minetest_current_modname"); + lua_getfield(L, LUA_REGISTRYINDEX, "current_modname"); return 1; } diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h index d72978dc6..cfdeea1e8 100644 --- a/src/script/lua_api/l_util.h +++ b/src/script/lua_api/l_util.h @@ -28,9 +28,8 @@ class ModApiUtil : public ModApiBase { private: /* NOTE: - The functions in this module are available through - minetest. in the in-game API as well as - engine. in the mainmenu API + The functions in this module are available in the in-game API + as well as in the mainmenu API. All functions that don't require either a Server or GUIEngine instance should be in here. diff --git a/src/script/scripting_game.cpp b/src/script/scripting_game.cpp index fccd10722..e716bc979 100644 --- a/src/script/scripting_game.cpp +++ b/src/script/scripting_game.cpp @@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "scripting_game.h" #include "server.h" -#include "filesys.h" #include "log.h" #include "cpp_api/s_internal.h" #include "lua_api/l_base.h" @@ -52,17 +51,9 @@ GameScripting::GameScripting(Server* server) //TODO add security - luaL_openlibs(getStack()); - SCRIPTAPI_PRECHECKHEADER - lua_pushstring(L, DIR_DELIM); - lua_setglobal(L, "DIR_DELIM"); - - // Create the main minetest table - lua_newtable(L); - lua_setglobal(L, "minetest"); - lua_getglobal(L, "minetest"); + lua_getglobal(L, "core"); int top = lua_gettop(L); lua_newtable(L); diff --git a/src/script/scripting_mainmenu.cpp b/src/script/scripting_mainmenu.cpp index 9afddd156..54b3133c5 100644 --- a/src/script/scripting_mainmenu.cpp +++ b/src/script/scripting_mainmenu.cpp @@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mods.h" #include "porting.h" #include "log.h" -#include "filesys.h" #include "cpp_api/s_internal.h" #include "lua_api/l_base.h" #include "lua_api/l_mainmenu.h" @@ -41,18 +40,11 @@ MainMenuScripting::MainMenuScripting(GUIEngine* guiengine) //TODO add security - luaL_openlibs(getStack()); - SCRIPTAPI_PRECHECKHEADER - lua_newtable(L); - lua_setglobal(L, "engine"); - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); int top = lua_gettop(L); - lua_pushstring(L, DIR_DELIM); - lua_setglobal(L, "DIR_DELIM"); - lua_newtable(L); lua_setglobal(L, "gamedata"); -- 2.25.1