Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
a4a6cc8e
Commit
a4a6cc8e
authored
10 years ago
by
kwolekr
Browse files
Options
Downloads
Patches
Plain Diff
builtin: Unify register wrapper functions and wrap clear_registered_* functions too
parent
0fd1ee03
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
builtin/game/register.lua
+23
-16
23 additions, 16 deletions
builtin/game/register.lua
doc/lua_api.txt
+15
-2
15 additions, 2 deletions
doc/lua_api.txt
with
38 additions
and
18 deletions
builtin/game/register.lua
+
23
−
16
View file @
a4a6cc8e
...
...
@@ -368,13 +368,6 @@ end
-- Callback registration
--
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
local function make_registration()
local t = {}
local registerfunc = function(func) table.insert(t, func) end
...
...
@@ -387,20 +380,34 @@ local function make_registration_reverse()
return t, registerfunc
end
local function make_registration_wrap(name)
local function make_registration_wrap(
reg_fn_name, clear_fn_
name)
local list = {}
local full_name = "
register_
"..name
local orig_func = core[full_name]
core[full_name] = function(def)
table.insert(list, def)
orig_func(def)
local orig_reg_fn = core[reg_fn_name]
core[reg_fn_name] = function(def)
local retval = orig_reg_fn(def)
if retval ~= nil then
if def.name ~= nil then
list[def.name] = def
else
list[retval] = def
end
end
return retval
end
local orig_clear_fn = core[clear_fn_name]
core[clear_fn_name] = function()
list = {}
return orig_clear_fn()
end
return list
end
core.registered_ores = make_registration_wrap("
o
re
")
core.registered_decorations = make_registration_wrap("
decoration
")
core.registered_biomes = make_registration_wrap("
register_biome
", "
clear_registered_biomes
")
core.registered_ores
= make_registration_wrap("
re
gister_ore
", "
clear_registered_ores
")
core.registered_decorations = make_registration_wrap("
register_
decoration
"
, "
clear_registered_decorations
"
)
core.registered_on_chat_messages, core.register_on_chat_message = make_registration()
core.registered_globalsteps, core.register_globalstep = make_registration()
...
...
This diff is collapsed.
Click to expand it.
doc/lua_api.txt
+
15
−
2
View file @
a4a6cc8e
...
...
@@ -417,10 +417,20 @@ the global `minetest.registered_*` tables.
* added to `minetest.registered_items[name]`
* `minetest.register_ore(ore definition)`
* added to `minetest.registered_ores`
* returns an integer uniquely identifying the registered ore
* added to `minetest.registered_ores` with the key of `ore.name`
* if `ore.name` is nil, the key is the returned ID
* `minetest.register_decoration(decoration definition)`
* added to `minetest.registered_decorations`
* returns an integer uniquely identifying the registered decoration
* added to `minetest.registered_decorations` with the key of `decoration.name`
* if `decoration.name` is nil, the key is the returned ID
* `minetest.clear_registered_ores()`
* clears all ores currently registered
* `minetest.clear_registered_decorations()`
* clears all decorations currently registered
Note that in some cases you will stumble upon things that are not contained
in these tables (e.g. when a mod has been removed). Always check for
...
...
@@ -1679,6 +1689,9 @@ Call these functions only at load time!
* Note: Item must already be defined, (opt)depend on the mod defining it.
* Example: `minetest.override_item("default:mese", {light_source=LIGHT_MAX})`
* `minetest.clear_registered_ores()`
* `minetest.clear_registered_decorations()`
### Global callback registration functions
Call these functions only at load time!
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment