ref stdcmd.lua, libvecn.cpp

This commit is contained in:
Cogi Asd
2024-07-08 14:32:59 +03:00
parent a039b2f667
commit 9a43940baf
2 changed files with 98 additions and 16 deletions
+50 -4
View File
@@ -26,24 +26,34 @@ console.add_command(
"help name:str=''",
"Show help infomation for the specified command",
function (args, kwargs)
local name = args[1]
if #name == 0 then
local commands = console.get_commands_list()
table.sort(commands)
local str = "Available commands:"
for i,k in ipairs(commands) do
str = str.."\n "..build_scheme(console.get_command_info(k))
end
return str.."\nuse 'help <command>'"
end
local command = console.get_command_info(name)
if command == nil then
return string.format("command %q not found", name)
end
local where = ""
local where = ":"
local str = SEPARATOR.."\n"..command.description.."\n"..name.." "
for i,arg in ipairs(command.args) do
for _, arg in ipairs(command.args) do
where = where.."\n "..arg.name.." - "..arg.type
if arg.optional then
str = str.."["..arg.name.."] "
where = where.." (optional)"
@@ -51,11 +61,47 @@ console.add_command(
str = str.."<"..arg.name.."> "
end
end
if #command.args then
if #command.args > 0 then
str = str.."\nwhere"..where
end
return str.."\n"..SEPARATOR
end
)
console.add_command(
"time.uptime",
"Get time elapsed since the engine started",
function()
local uptime = time.uptime()
local years = math.floor(uptime / 31536000)
local days = math.floor((uptime % 31536000) / 86400) % 365
local hours = math.floor((uptime % 86400) / 3600) % 24
local minutes = math.floor((uptime % 3600) / 60) % 60
local seconds = math.floor(uptime % 60)
local formatted_uptime = ""
if years > 0 then
formatted_uptime = formatted_uptime .. years .. "y "
end
if days > 0 or years > 0 then
formatted_uptime = formatted_uptime .. days .. "d "
end
if hours > 0 or days > 0 or years > 0 then
formatted_uptime = formatted_uptime .. hours .. "h "
end
if minutes > 0 or hours > 0 or days > 0 or years > 0 then
formatted_uptime = formatted_uptime .. minutes .. "m "
end
if seconds > 0 or minutes > 0 or hours > 0 or days > 0 or years > 0 then
formatted_uptime = formatted_uptime .. seconds .. "s"
end
return uptime .. " (" .. formatted_uptime .. ")"
end
)