summaryrefslogtreecommitdiff
path: root/builtin/common
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-04-27 21:02:48 -0400
committerShadowNinja <shadowninja@minetest.net>2014-05-08 13:02:04 -0400
commitc4359ff65cd8e4e754442b9f2ef7051a8eaa4241 (patch)
treefeaad8be8c36cc4a0abdbe8d7b84db3ac68ed87e /builtin/common
parent1cd512913e4d4ad1fb43d4b6e3d7971bb6c67528 (diff)
downloadminetest-c4359ff65cd8e4e754442b9f2ef7051a8eaa4241.tar.gz
minetest-c4359ff65cd8e4e754442b9f2ef7051a8eaa4241.tar.bz2
minetest-c4359ff65cd8e4e754442b9f2ef7051a8eaa4241.zip
Use "core" namespace internally
Diffstat (limited to 'builtin/common')
-rw-r--r--builtin/common/async_event.lua10
-rw-r--r--builtin/common/misc_helpers.lua64
-rw-r--r--builtin/common/serialize.lua10
3 files changed, 38 insertions, 46 deletions
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