Skip to content

Commit

Permalink
Merge pull request #6 from Hacknique/fix/namespaces
Browse files Browse the repository at this point in the history
Fixed `registered_commands` namespace
  • Loading branch information
JamesClarke7283 authored Oct 15, 2023
2 parents 1bd9c45 + bd7fd4c commit 8bac7f1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
10 changes: 3 additions & 7 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@

-- global mod namespace
modular_computers = {}
modular_computers.internal = {}
modular_computers.mod = {}

modular_computers.mod_storage = minetest.get_mod_storage()

modular_computers.mod = {}
modular_computers.mod.name = minetest.get_current_modname()
modular_computers.mod.path = minetest.get_modpath(modular_computers.mod.name)

modular_computers.registered_commands = {}

modular_computers.S = minetest.get_translator(modular_computers.mod.name)

-- Load the scripts
dofile(modular_computers.mod.path .. "/src/utilities.lua")
dofile(modular_computers.mod.path .. "/src/os/api/cli.lua")
dofile(modular_computers.mod.path .. "/src/os/bin/init.lua")
dofile(modular_computers.mod.path .. "/src/os/init.lua")
dofile(modular_computers.mod.path .. "/src/nodes/init.lua")
dofile(modular_computers.mod.path .. "/src/items/init.lua")
dofile(modular_computers.mod.path .. "/src/os/init.lua")

2 changes: 1 addition & 1 deletion src/nodes/computer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ minetest.register_on_player_receive_fields(

-- Execute the command
local args = string.split(command, "%s+", false, -1, true)
local def = modular_computers.registered_commands[args[1]]
local def = modular_computers.internal.command.registered_commands[args[1]]
if def ~= nil then
local stdin, stdout, stderr, exit_code = def.func(player,#args - 1,unpack(args,2))
if stderr ~= "" then
Expand Down
11 changes: 9 additions & 2 deletions src/os/api/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
Copyright (c) 2023 James Clarke <james@jamesdavidclarke.com>
]]

function modular_computers.register_command(name, def)
modular_computers.registered_commands[name] = def
modular_computers.command = {}
modular_computers.internal.command = {registered_commands = {}}

function modular_computers.command.register(name, callback)
modular_computers.internal.command.registered_commands[name] = callback




end
2 changes: 1 addition & 1 deletion src/os/bin/echo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Copyright (c) 2023 James Clarke <james@jamesdavidclarke.com>
]]

modular_computers.register_command("echo", {
modular_computers.command.register("echo", {
func = function(player, argc, ...)
return "", table.concat({...}, " ") .. "\n", "", 0
end,
Expand Down

0 comments on commit 8bac7f1

Please sign in to comment.