update instructions

M  README.md
M  faden.lua
M  standardbefehlssatz.lua
M  util/standartbefehlssatz_doc.lua
This commit is contained in:
Hybrid Dog 2017-02-03 23:20:22 +01:00
parent f566b8b557
commit c821cafc14
4 changed files with 99 additions and 7 deletions

View File

@ -145,4 +145,4 @@ end
TODO:
* add string. instructions
* add inc,dec,sub,div
* metatable

View File

@ -85,7 +85,9 @@ return function(faden_manip, parsed)
try_rebirth = function(self)
if minetest.get_us_time() >= self.rebirth then
self:continue()
return true
end
return false
end,
exit = function(self)
self:flush()

View File

@ -9,6 +9,10 @@ s = {
return true, params[2]
end,
xchg = function(params)
return true, params[2], params[1]
end,
getvar = function(params, faden)
local p = params[1]
if type(p) ~= "string" then
@ -29,7 +33,12 @@ s = {
return true, p1 + p2
end
if t1 == "boolean" then
return true, p1 and p2
for _,k in pairs(params) do
if k then
return true, true
end
end
return true, false
end
if t1 == "string" then
if #p1 + #p2 > faden.strlen_max then
@ -40,6 +49,22 @@ s = {
return false, UAT
end,
sub = function(params)
local b = params[2]
b = b and tonumber(b)
local t2 = type(b)
if t2 ~= "number" then
return false, UAT
end
local t1 = type(params[1])
if t1 == "number" then
return true, params[1] - b
end
if t1 == "string" then
return true, params[1]:sub(b, params[3] and tonumber(params[3]))
end
end,
mul = function(params)
local p1,p2 = unpack(params)
local t1 = type(p1)
@ -59,11 +84,39 @@ s = {
return true, p1 * p2
end
if t1 == "boolean" then
return true, p1 or p2
for _,k in pairs(params) do
if not k then
return true, false
end
end
return true, p1 and p2 -- nil is tested in the first two params
end
return false, UAT
end,
div = function(params)
local p1,p2 = unpack(params)
if type(p1) ~= "number"
or type(p2) ~= "number" then
return false, UAT
end
return true, p1 / p2
end,
inc = function(params)
if type(params[1]) ~= "number" then
return false, UAT
end
return true, params[1] + 1
end,
dec = function(params)
if type(params[1]) ~= "number" then
return false, UAT
end
return true, params[1] - 1
end,
neg = function(params)
local v = params[1]
local t = type(v)
@ -74,7 +127,7 @@ s = {
return true, not v
end
if t == "string" then
return true, v:rev()
return true, v:rev() -- does string.rev exist?
end
return false, UAT
end,
@ -190,6 +243,10 @@ s = {
return true, p1 < p2
end,
greater = function(params)
return s.less{params[2], params[1]}
end,
usleep = function(params, faden)
local p = params[1]
if type(p) ~= "number" then
@ -217,7 +274,15 @@ s = {
end,
tostring = function(params)
return true, tostring(params[1])
return true, params[1] and tostring(params[1]) or nil
end,
tonumber = function(params)
return true, params[1] and tonumber(params[1])
end,
toboolean = function(params)
return true, params[1] and true or false
end,
print = function(params, faden)
@ -259,4 +324,20 @@ for i = 1,#to_math_fcts do
end
end
local abbreviations = {
mov = ":=",
add = "+",
sub = "-",
mul = "*",
div = "/",
inc = "++",
dec = "--",
neg = "!",
less = "<",
equal = "==",
jmp = "@",
usleep = "...",
}
-- TODO set metatable
return s

View File

@ -13,13 +13,19 @@ local types = {
local instr = {
{"mov", "<v to>, <e from>", "Copies from into to."},
{"xchg", "<v a>, <v b>", "Switches a with b."},
{"getvar", "<vs varname>[, <ve exists>]", "Sets varname to the current variable called <varname> if it's set. If exists is passed, it's set to a bool indicating whether the variable was set."},
{"add", "<vn to>, <n from>", "to += from"},
{"add", "<vb to>, <b from>", "to = to and from"},
{"add", "<vb to>[, <b ba>[, <b bb>[…]]]", "to indicates whether at least one of the arguments is true"},
{"add", "<vs to>, <s from>", "to = to .. from"},
{"sub", "<vn num>, <n tosub>", "num -= tosub"},
{"sub", "<vs str>, <n start>[, <n end>]", "str = str:sub(start, end)"},
{"mul", "<vn to>, <n from>", "to *= from"},
{"mul", "<vb to>, <b from>", "to = to or from"},
{"mul", "<vb to>[, <b ba>[, <b bb>[…]]]", "to indicates whether all of the arguments are true"},
{"mul", "<vs str>, <n cnt>", "str = str:rep(from)"},
{"div", "<vn num>, <n todiv>", "num /= todiv"},
{"inc", "<vn num>", "++num"},
{"dec", "<vn num>", "--num"},
{"neg", "<vn num>", "num = -num"},
{"neg", "<vb var>", "var = not var"},
{"neg", "<vs str>", "str = str:rev()"},
@ -33,10 +39,13 @@ local instr = {
{"equal", "<v a>, <e b>", "a = a == b"},
{"less", "<vn a>, <n b>", "a = a < b; after executing, a is a bool"},
{"less", "<vs a>, <s b>", "a = a < b; less also works for strings"},
{"greater", "<v a>, <e b>", "executes less b,a"},
{"usleep", "<n t>", "aborts the program for at least floor(max(0, t)) ms"},
{"sleep", "<n t>", "executes usleep with t * 1000000 as argument"},
{"get_us_time", "<v to>", "stores minetest.get_us_time() into to; can be used to measure time differences"},
{"tostring", "<ve var>", "var = tostring(var)"},
{"tonumber", "<ve var>", "var = tonumber(var)"},
{"toboolean", "<ve var>", "var = var and true or false"},
{"print", "<e a>[, <e b>[, <e c>[…]]]", "adds variables to the log, seperated by \\t, \\n is added at the end"},
{"flush", "", "Output the log, this should vary for every mod."},
}