add commands to terminal
This commit is contained in:
parent
d0a4ace94e
commit
ef2ceed755
|
@ -0,0 +1,16 @@
|
||||||
|
computers.registered_commands = {}
|
||||||
|
|
||||||
|
function computers.register_command(modpath)
|
||||||
|
local func = dofile(modpath .. "/init.lua")
|
||||||
|
local f = io.open(modpath .. "/conf.json")
|
||||||
|
local conf = minetest.parse_json(f:read("*all"))
|
||||||
|
f:close()
|
||||||
|
if func and computers.os.version >= conf.engine then computers.registered_commands[conf.name] = func end
|
||||||
|
end
|
||||||
|
|
||||||
|
--load default commands
|
||||||
|
local dirs = minetest.get_dir_list(computers.modpath .. "/commands", true)
|
||||||
|
|
||||||
|
for _, dir in pairs(dirs) do
|
||||||
|
computers.register_command(computers.modpath .. "/commands/" .. dir)
|
||||||
|
end
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"name": "echo",
|
||||||
|
"license": "MIT",
|
||||||
|
"version": 0.1,
|
||||||
|
"engine": 0.3
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
function echo(input)
|
||||||
|
return input
|
||||||
|
end
|
||||||
|
|
||||||
|
return echo
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"name": "test",
|
||||||
|
"license": "MIT",
|
||||||
|
"version": 0.1,
|
||||||
|
"engine": 100000000
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
function test()
|
||||||
|
--minetest.chat_send_all("test")
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
return test
|
|
@ -122,16 +122,32 @@ function computers.load_gui(pos, node, clicker)
|
||||||
border = false,
|
border = false,
|
||||||
},
|
},
|
||||||
on_event = function(form, player, element, value)
|
on_event = function(form, player, element, value)
|
||||||
minetest.chat_send_all("value: " .. value)
|
|
||||||
local cindex = futil.get_index_by_name(form, "terminal_ctn")
|
local cindex = futil.get_index_by_name(form, "terminal_ctn")
|
||||||
local eindex = futil.get_index_by_name(form[cindex], "terminal_output")
|
local eindex = futil.get_index_by_name(form[cindex], "terminal_output")
|
||||||
local text = form[cindex][eindex].default
|
local text = form[cindex][eindex].default
|
||||||
form[cindex][eindex].default = text .. "user:~$ " .. value .. "\n"
|
--form[cindex][eindex].default = text .. "user:~$ " .. value .. "\n"
|
||||||
|
|
||||||
if value == "clear" then
|
if value == "clear" then
|
||||||
form[cindex][eindex].default = "user:~$\n"
|
form[cindex][eindex].default = "user:~$\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local cdata = value:split(" ", false, 1)
|
||||||
|
|
||||||
|
if computers.registered_commands[cdata[1]] then
|
||||||
|
form[cindex][eindex].default = text .. "user:~$ " .. cdata[1] .. "\n"
|
||||||
|
text = form[cindex][eindex].default
|
||||||
|
local output = computers.registered_commands[cdata[1]](cdata[2])
|
||||||
|
if output and output ~= "" and type(output) == "string" then
|
||||||
|
form[cindex][eindex].default = text .. output .. "\n"
|
||||||
|
end
|
||||||
|
elseif value == "clear" then
|
||||||
|
form[cindex][eindex].default = "user:~$\n"
|
||||||
|
elseif value == "" then
|
||||||
|
form[cindex][eindex].default = text .. "user:~$\n"
|
||||||
|
else
|
||||||
|
form[cindex][eindex].default = text .. "user:~$ " .. value .. "\nERROR: command not found\n"
|
||||||
|
end
|
||||||
|
|
||||||
return form
|
return form
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
computers = {}
|
computers = {}
|
||||||
computers.modpath = minetest.get_modpath("computers")
|
computers.modpath = minetest.get_modpath("computers")
|
||||||
|
|
||||||
|
computers.os = {
|
||||||
|
version = 0.3,
|
||||||
|
name = "kuto",
|
||||||
|
authors = {"wsor", "luk3yx"},
|
||||||
|
license = "MIT",
|
||||||
|
}
|
||||||
|
|
||||||
dofile(computers.modpath .. "/old_stuff/init.lua")
|
dofile(computers.modpath .. "/old_stuff/init.lua")
|
||||||
|
|
||||||
dofile(computers.modpath .. "/formspec.lua")
|
dofile(computers.modpath .. "/formspec.lua")
|
||||||
|
dofile(computers.modpath .. "/commands.lua")
|
||||||
dofile(computers.modpath .. "/gui.lua")
|
dofile(computers.modpath .. "/gui.lua")
|
||||||
dofile(computers.modpath .. "/demo.lua")
|
dofile(computers.modpath .. "/demo.lua")
|
||||||
|
|
Loading…
Reference in New Issue