From 3eb0f97115eb3f38fd0dc096a40fd558cc2e6ce7 Mon Sep 17 00:00:00 2001 From: Alexander Chibrikin Date: Wed, 21 Jan 2026 18:57:22 +0300 Subject: [PATCH] Extract `logging.lua` & `registration/environment.lua` into `./core_namespace/`. Relates to #1 --- core_namespace.lua | 126 +------------------- core_namespace/logging.lua | 22 ++++ core_namespace/registration/environment.lua | 122 +++++++++++++++++++ 3 files changed, 147 insertions(+), 123 deletions(-) create mode 100644 core_namespace/logging.lua create mode 100644 core_namespace/registration/environment.lua diff --git a/core_namespace.lua b/core_namespace.lua index d89299c..f9b11fc 100644 --- a/core_namespace.lua +++ b/core_namespace.lua @@ -305,134 +305,14 @@ function core.translate(textdomain, str, ...) end -- Logging: - ---- * Equivalent to `core.log(table.concat({...}, "\t"))` ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4458-L4459) ---- @param ... any -function core.debug(...) end - ---- @alias LogLevel ---- | "none" ---- | "error" ---- | "warning" ---- | "action" ---- | "info" ---- | "verbose" - ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4460-L4462) ---- ---- @overload fun(text:string) ---- @param level? LogLevel # [Optional] is one of `"none"`, `"error"`, `"warning"`, `"action"`, `"info"`, or `"verbose"`. Default is `"none"`. ---- @param text string -function core.log(level, text) end - +-- see ./core_namespace/logging.lua -- Registration functions: - -- Environment: +-- see ./core_namespace/registration/environment.lua + ---- @param name string technical node name (":"). ---- @param node_definition NodeDefinition table with node definition properties. ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4471-L4471) -function core.register_node(name, node_definition) end ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4472-L4472) ---- @param item_definition ItemDefinition -function core.register_craftitem(name, item_definition) end ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4473-L4473) ---- @param name string ---- @param item_definition ItemDefinition -function core.register_tool(name, item_definition) end ---- * Overrides fields of an item registered with register_node/tool/craftitem. ---- * Note: Item must already be defined, (opt)depend on the mod defining it. ---- * Example: `core.override_item("default:mese", ---- {light_source=core.LIGHT_MAX})` ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4474-L4478) ---- @param name string ---- @param redefinition ItemDefinition|NodeDefinition -function core.override_item(name, redefinition) end ---- * Unregisters the item from the engine, and deletes the entry with key ---- `name` from `core.registered_items` and from the associated item table ---- according to its nature: `core.registered_nodes`, etc. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4479-L4482) -function core.unregister_item(name) end ---- @param name string ---- @param entity_definition EntityDefinition ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4483-L4483) -function core.register_entity(name, entity_definition) end ---- @param abm_definition ABMDefinition ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4484-L4484) -function core.register_abm(abm_definition) end ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4485-L4485) -function core.register_lbm(lbm_definition) end ---- * Also use this to set the 'mapgen aliases' needed in a game for the core ---- mapgens. See [Mapgen aliases] section above. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4486-L4488) ----@param alias string @itemstring ----@param original_name string @itemstring -function core.register_alias(alias, original_name) end ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4489-L4489) -function core.register_alias_force(alias, original_name) end ---- * Returns an integer object handle uniquely identifying the registered ---- ore on success. ---- * The order of ore registrations determines the order of ore generation. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4490-L4493) -function core.register_ore(ore_definition) end ---- * Returns an integer object handle uniquely identifying the registered ---- biome on success. To get the biome ID, use `core.get_biome_id`. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4494-L4496) -function core.register_biome(biome_definition) end ---- * Unregisters the biome from the engine, and deletes the entry with key ---- `name` from `core.registered_biomes`. ---- * Warning: This alters the biome to biome ID correspondences, so any ---- decorations or ores using the 'biomes' field must afterwards be cleared ---- and re-registered. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4497-L4502) -function core.unregister_biome(name) end ---- * Returns an integer object handle uniquely identifying the registered ---- decoration on success. To get the decoration ID, use ---- `core.get_decoration_id`. ---- * The order of decoration registrations determines the order of decoration ---- generation. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4503-L4508) -function core.register_decoration(decoration_definition) end ---- * Returns an integer object handle uniquely identifying the registered ---- schematic on success. ---- * If the schematic is loaded from a file, the `name` field is set to the ---- filename. ---- * If the function is called when loading the mod, and `name` is a relative ---- path, then the current mod path will be prepended to the schematic ---- filename. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4509-L4516) -function core.register_schematic(schematic_definition) end ---- * Clears all biomes currently registered. ---- * Warning: Clearing and re-registering biomes alters the biome to biome ID ---- correspondences, so any decorations or ores using the 'biomes' field must ---- afterwards be cleared and re-registered. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4517-L4521) -function core.clear_registered_biomes() end ---- * Clears all decorations currently registered. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4522-L4523) -function core.clear_registered_decorations() end ---- * Clears all ores currently registered. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4524-L4525) -function core.clear_registered_ores() end ---- * Clears all schematics currently registered. ---- ---- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4526-L4527) -function core.clear_registered_schematics() end -- Gameplay: --- * Check recipe table syntax for different types below. diff --git a/core_namespace/logging.lua b/core_namespace/logging.lua new file mode 100644 index 0000000..9099791 --- /dev/null +++ b/core_namespace/logging.lua @@ -0,0 +1,22 @@ + +--- Equivalent to `core.log(table.concat({...}, "\t"))` +--- +--- Calls `core.log()` with all arguments converted to string and separated by tabs (similar to print). +--- +--- @param ... any +function core.debug(...) end + +--- @alias LogLevel +--- | "none" +--- | "error" +--- | "warning" +--- | "action" +--- | "info" +--- | "verbose" + +--- Logs a message at the specified log level. +--- +--- @overload fun(text:string) +--- @param level? LogLevel # [Optional] is one of `"none"`, `"error"`, `"warning"`, `"action"`, `"info"`, or `"verbose"`. Default is `"none"`. +--- @param text string +function core.log(level, text) end diff --git a/core_namespace/registration/environment.lua b/core_namespace/registration/environment.lua new file mode 100644 index 0000000..e7177c2 --- /dev/null +++ b/core_namespace/registration/environment.lua @@ -0,0 +1,122 @@ +--- @meta + + +--- * register a node with its definition +--- * Note: you must pass a clean table that hasn't already been used for another registration to this function, as it will be modified. +--- @param name string technical node name (":"). +--- @param node_definition NodeDefinition table with node definition properties. +function core.register_node(name, node_definition) end + + +--- * register an item with its definition +--- * Note: you must pass a clean table that hasn't already been used for another registration to this function, as it will be modified. +--- @param name string technical item name (":"). +--- @param item_definition ItemDefinition table with item definition properties. +function core.register_craftitem(name, item_definition) end + +--- * register a tool item with its definition +--- * Note: you must pass a clean table that hasn't already been used for another registration to this function, as it will be modified. +--- @param name string +--- @param item_definition ItemDefinition +function core.register_tool(name, item_definition) end + +--- Overrides fields of an item registered with register_node/tool/craftitem. +--- * `redefinition` is a table of fields `[name] = new_value`, overwriting fields of or adding fields to the existing definition. +--- * Note: Item must already be defined, (opt)depend on the mod defining it. +--- * Example: `core.override_item("default:mese", { light_source = core.LIGHT_MAX }, { "sounds" })`: +--- Overwrites the `light_source` field, removes the `sounds` from the definition of the mese block. +--- +--- @param name string +--- @param redefinition ItemDefinition|NodeDefinition +function core.override_item(name, redefinition) end + +--- Unregisters the item from the engine, and deletes the entry with key +--- `name` from `core.registered_items` and from the associated item table +--- according to its nature (e.g. `core.registered_nodes`) +--- +--- @param name string +function core.unregister_item(name) end + +--- @param name string +--- @param entity_definition EntityDefinition +function core.register_entity(name, entity_definition) end + +--- @param abm_definition ABMDefinition +function core.register_abm(abm_definition) end + +--- @param lbm_definition LBMDefinition +function core.register_lbm(lbm_definition) end + +--- * Also use this to set the 'mapgen aliases' needed in a game for the core +--- mapgens. See [Mapgen aliases](https://api.luanti.org/aliases/#mapgen-aliases) section. +--- +--- @param alias string @itemstring (`":"`). For renaming: its old name. +--- @param original_name string @itemstring (`":"`). For renaming: its new name. +function core.register_alias(alias, original_name) end + +--- * Forces an alias to be created, even if an alias with the same name +--- already exists. +--- @param alias string @itemstring (`":"`). For renaming: its old name. +--- @param original_name string @itemstring (`":"`). For renaming: its new name. +function core.register_alias_force(alias, original_name) end + +--- * Returns an integer object handle uniquely identifying the registered ore on success. +--- * The order of ore registrations determines the order of ore generation. +--- +--- @param ore_definition OreDefinition +--- @return integer +function core.register_ore(ore_definition) end + +--- * Returns an integer object handle uniquely identifying the registered +--- biome on success. To get the biome ID, use `core.get_biome_id`. +--- +--- @param biome_definition BiomeDefinition +--- @return integer +function core.register_biome(biome_definition) end + +--- * Unregisters the biome from the engine, and deletes the entry with key +--- `name` from `core.registered_biomes`. +--- * Warning: This alters the biome to biome ID correspondences, so any +--- decorations or ores using the 'biomes' field must afterwards be cleared +--- and re-registered. +--- +--- @param name string +function core.unregister_biome(name) end + +--- * Returns an integer object handle uniquely identifying the registered +--- decoration on success. To get the decoration ID, use +--- `core.get_decoration_id`. +--- * The order of decoration registrations determines the order of decoration +--- generation. +--- +--- @param decoration_definition DecorationDefinition +--- @return integer +function core.register_decoration(decoration_definition) end + +--- * Returns an integer object handle uniquely identifying the registered +--- schematic on success. +--- * If the schematic is loaded from a file, the `name` field is set to the +--- filename. +--- * If the function is called when loading the mod, and `name` is a relative +--- path, then the current mod path will be prepended to the schematic +--- filename. +--- +--- @param schematic SchematicSpecifier|string +--- @param replacements? table? +--- @return integer +function core.register_schematic(schematic, replacements) end + +--- * Clears all biomes currently registered. +--- * Warning: Clearing and re-registering biomes alters the biome to biome ID +--- correspondences, so any decorations or ores using the 'biomes' field must +--- afterwards be cleared and re-registered. +function core.clear_registered_biomes() end + +--- * Clears all decorations currently registered. +function core.clear_registered_decorations() end + +--- * Clears all ores currently registered. +function core.clear_registered_ores() end + +--- * Clears all schematics currently registered. +function core.clear_registered_schematics() end