Skip to content
Permalink
Browse files

Use "core" namespace internally

  • Loading branch information
ShadowNinja committed Apr 28, 2014
1 parent 1cd5129 commit c4359ff65cd8e4e754442b9f2ef7051a8eaa4241
Showing with 812 additions and 843 deletions.
  1. +1 −2 builtin/async/init.lua
  2. +4 −6 builtin/common/async_event.lua
  3. +29 −35 builtin/common/misc_helpers.lua
  4. +5 −5 builtin/common/serialize.lua
  5. +53 −53 builtin/game/auth.lua
  6. +194 −194 builtin/game/chatcommands.lua
  7. +19 −19 builtin/game/deprecated.lua
  8. +4 −4 builtin/game/detached_inventory.lua
  9. +42 −40 builtin/game/falling.lua
  10. +4 −4 builtin/game/features.lua
  11. +15 −15 builtin/game/forceloading.lua
  12. +80 −80 builtin/game/item.lua
  13. +10 −10 builtin/game/item_entity.lua
  14. +35 −35 builtin/game/misc.lua
  15. +19 −19 builtin/game/privileges.lua
  16. +90 −90 builtin/game/register.lua
  17. +6 −6 builtin/game/statbars.lua
  18. +9 −9 builtin/game/static_spawn.lua
  19. +1 −3 builtin/init.lua
  20. +4 −3 builtin/mainmenu/init.lua
  21. +3 −11 builtin/mainmenu/modmgr.lua
  22. +4 −4 doc/menu_lua_api.txt
  23. +4 −4 src/script/common/c_content.cpp
  24. +2 −2 src/script/common/c_internal.cpp
  25. +6 −13 src/script/cpp_api/s_async.cpp
  26. +19 −9 src/script/cpp_api/s_base.cpp
  27. +13 −13 src/script/cpp_api/s_entity.cpp
  28. +8 −8 src/script/cpp_api/s_env.cpp
  29. +2 −2 src/script/cpp_api/s_inventory.cpp
  30. +8 −8 src/script/cpp_api/s_item.cpp
  31. +4 −4 src/script/cpp_api/s_mainmenu.cpp
  32. +16 −16 src/script/cpp_api/s_player.cpp
  33. +5 −5 src/script/cpp_api/s_server.cpp
  34. +43 −43 src/script/lua_api/l_env.cpp
  35. +34 −34 src/script/lua_api/l_env.h
  36. +1 −1 src/script/lua_api/l_inventory.cpp
  37. +1 −1 src/script/lua_api/l_inventory.h
  38. +3 −3 src/script/lua_api/l_item.cpp
  39. +1 −1 src/script/lua_api/l_item.h
  40. +3 −3 src/script/lua_api/l_mapgen.cpp
  41. +3 −3 src/script/lua_api/l_mapgen.h
  42. +1 −1 src/script/lua_api/l_server.cpp
  43. +2 −3 src/script/lua_api/l_util.h
  44. +1 −10 src/script/scripting_game.cpp
  45. +1 −9 src/script/scripting_mainmenu.cpp
@@ -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)
@@ -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

0 comments on commit c4359ff

Please sign in to comment.
You can’t perform that action at this time.