more instructions, string length test and dont try executing nil

M  faden.lua
M  standardbefehlssatz.lua
This commit is contained in:
Hybrid Dog 2016-12-29 14:14:20 +01:00
parent 641aa73686
commit 79fd928b68
2 changed files with 82 additions and 5 deletions

View File

@ -2,7 +2,11 @@ local function befehl_ausfuhren(faden)
local is = faden.is
local imms = faden.imms
local vars = faden.vars
local befehl, args = unpack(faden.liste[faden.ip])
local anw = faden.liste[faden.ip]
if not anw then
return false, "Invalid instruction pointer"
end
local befehl, args = unpack(anw)
for i = 1,#is do
local bfunk = is[i][befehl]
if bfunk then
@ -64,8 +68,9 @@ return function(faden_manip, parsed)
log = "",
vars = {pi = math.pi},
ip = 1,
sp = 50,
sb = 50,
sp = 3500,
sb = 3500,
strlen_max = 2000,
stack = {},
is = {pdisc.standard_befehlssatz},
suscitate = programm_ausfuhren,
@ -93,6 +98,12 @@ return function(faden_manip, parsed)
if parsed then
faden.imms = parsed[1]
faden.liste = parsed[2]
if not faden.liste[1] then
faden.suscitate = function(self)
self.log = self.log .. "Nothing to execute.\n"
self:exit()
end
end
end
faden_manip(faden)
return faden

View File

@ -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