Use "core" namespace internally
This commit is contained in:
@@ -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)
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user