mirror of
https://github.com/HybridDog/pdisc.git
synced 2025-07-01 15:50:44 +02:00
more instructions, string length test and dont try executing nil
M faden.lua M standardbefehlssatz.lua
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
local WNOA = "wrong number of arguments"
|
||||
local UAT = "unsupported argument type"
|
||||
local SE = "error with cmd-cmd executing: "
|
||||
local STRL = "attempt on exceeding maximum string length"
|
||||
|
||||
local s
|
||||
s = {
|
||||
@ -11,7 +12,7 @@ s = {
|
||||
return true, params[2]
|
||||
end,
|
||||
|
||||
add = function(params)
|
||||
add = function(params, faden)
|
||||
if #params ~= 2 then
|
||||
return false, WNOA
|
||||
end
|
||||
@ -28,6 +29,9 @@ s = {
|
||||
if t1 == "boolean" then
|
||||
return true, p1 and p2
|
||||
end
|
||||
if #p1 + #p2 > faden.strlen_max then
|
||||
return false, STRL
|
||||
end
|
||||
return true, p1 .. p2
|
||||
end,
|
||||
|
||||
@ -40,6 +44,9 @@ s = {
|
||||
local t2 = type(p2)
|
||||
if t1 == "string"
|
||||
and t2 == "number" then
|
||||
if #p1 * p2 > faden.strlen_max then
|
||||
return false, STRL
|
||||
end
|
||||
return true, p1:rep(p2)
|
||||
end
|
||||
if t1 ~= t2 then
|
||||
@ -125,6 +132,33 @@ s = {
|
||||
return true
|
||||
end,
|
||||
|
||||
call = function(params, faden)
|
||||
if #params ~= 1 then
|
||||
return false, WNOA
|
||||
end
|
||||
local subsucc,msg = s.push(faden.ip + 1, faden)
|
||||
if not subsucc then
|
||||
return false, SE .. msg
|
||||
end
|
||||
subsucc,msg = s.jmp(params, faden)
|
||||
if not subsucc then
|
||||
return false, SE .. msg
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
ret = function(_, faden)
|
||||
local subsucc,msg = s.pop({true}, faden)
|
||||
if not subsucc then
|
||||
return false, SE .. msg
|
||||
end
|
||||
subsucc,msg = s.jmp({msg}, faden)
|
||||
if not subsucc then
|
||||
return false, SE .. msg
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
push = function(params, faden)
|
||||
local pc = #params
|
||||
if pc == 0 then
|
||||
@ -192,6 +226,21 @@ s = {
|
||||
return true
|
||||
end,
|
||||
|
||||
sleep = function(params, faden)
|
||||
if #params ~= 1 then
|
||||
return false, WNOA
|
||||
end
|
||||
local p = params[1]
|
||||
if type(p) ~= "number" then
|
||||
return false, UAT
|
||||
end
|
||||
subsucc,msg = s.usleep({p * 1000000}, faden)
|
||||
if not subsucc then
|
||||
return false, SE .. msg
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
get_us_time = function()
|
||||
return true, minetest.get_us_time()
|
||||
end,
|
||||
@ -216,7 +265,7 @@ s = {
|
||||
end,
|
||||
}
|
||||
|
||||
local so_math_fcts = {"sin", "asin", "cos", "acos", "tan", "atan",
|
||||
local so_math_fcts = {"sin", "asin", "cos", "acos", "tan", "atan", "exp", "log",
|
||||
"abs", "sign", "floor", "ceil"}
|
||||
for i = 1,#so_math_fcts do
|
||||
i = so_math_fcts[i]
|
||||
@ -231,4 +280,21 @@ for i = 1,#so_math_fcts do
|
||||
return true, math[i](p)
|
||||
end
|
||||
end
|
||||
|
||||
local to_math_fcts = {"pow"}
|
||||
for i = 1,#to_math_fcts do
|
||||
i = to_math_fcts[i]
|
||||
s[i] = function(params)
|
||||
if #params ~= 2 then
|
||||
return false, WNOA
|
||||
end
|
||||
local p1,p2 = unpack(params)
|
||||
if type(p1) ~= "number"
|
||||
or type(p2) ~= "number" then
|
||||
return false, UAT
|
||||
end
|
||||
return true, math[i](p1, p2)
|
||||
end
|
||||
end
|
||||
|
||||
return s
|
||||
|
Reference in New Issue
Block a user