mirror of
https://github.com/HybridDog/pdisc.git
synced 2025-01-09 17:10:18 +01:00
update instructions
M README.md M faden.lua M standardbefehlssatz.lua M util/standartbefehlssatz_doc.lua
This commit is contained in:
parent
f566b8b557
commit
c821cafc14
@ -145,4 +145,4 @@ end
|
|||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
* add string. instructions
|
* add string. instructions
|
||||||
* add inc,dec,sub,div
|
* metatable
|
||||||
|
@ -85,7 +85,9 @@ return function(faden_manip, parsed)
|
|||||||
try_rebirth = function(self)
|
try_rebirth = function(self)
|
||||||
if minetest.get_us_time() >= self.rebirth then
|
if minetest.get_us_time() >= self.rebirth then
|
||||||
self:continue()
|
self:continue()
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end,
|
end,
|
||||||
exit = function(self)
|
exit = function(self)
|
||||||
self:flush()
|
self:flush()
|
||||||
|
@ -9,6 +9,10 @@ s = {
|
|||||||
return true, params[2]
|
return true, params[2]
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
xchg = function(params)
|
||||||
|
return true, params[2], params[1]
|
||||||
|
end,
|
||||||
|
|
||||||
getvar = function(params, faden)
|
getvar = function(params, faden)
|
||||||
local p = params[1]
|
local p = params[1]
|
||||||
if type(p) ~= "string" then
|
if type(p) ~= "string" then
|
||||||
@ -29,7 +33,12 @@ s = {
|
|||||||
return true, p1 + p2
|
return true, p1 + p2
|
||||||
end
|
end
|
||||||
if t1 == "boolean" then
|
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
|
end
|
||||||
if t1 == "string" then
|
if t1 == "string" then
|
||||||
if #p1 + #p2 > faden.strlen_max then
|
if #p1 + #p2 > faden.strlen_max then
|
||||||
@ -40,6 +49,22 @@ s = {
|
|||||||
return false, UAT
|
return false, UAT
|
||||||
end,
|
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)
|
mul = function(params)
|
||||||
local p1,p2 = unpack(params)
|
local p1,p2 = unpack(params)
|
||||||
local t1 = type(p1)
|
local t1 = type(p1)
|
||||||
@ -59,11 +84,39 @@ s = {
|
|||||||
return true, p1 * p2
|
return true, p1 * p2
|
||||||
end
|
end
|
||||||
if t1 == "boolean" then
|
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
|
end
|
||||||
return false, UAT
|
return false, UAT
|
||||||
end,
|
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)
|
neg = function(params)
|
||||||
local v = params[1]
|
local v = params[1]
|
||||||
local t = type(v)
|
local t = type(v)
|
||||||
@ -74,7 +127,7 @@ s = {
|
|||||||
return true, not v
|
return true, not v
|
||||||
end
|
end
|
||||||
if t == "string" then
|
if t == "string" then
|
||||||
return true, v:rev()
|
return true, v:rev() -- does string.rev exist?
|
||||||
end
|
end
|
||||||
return false, UAT
|
return false, UAT
|
||||||
end,
|
end,
|
||||||
@ -190,6 +243,10 @@ s = {
|
|||||||
return true, p1 < p2
|
return true, p1 < p2
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
greater = function(params)
|
||||||
|
return s.less{params[2], params[1]}
|
||||||
|
end,
|
||||||
|
|
||||||
usleep = function(params, faden)
|
usleep = function(params, faden)
|
||||||
local p = params[1]
|
local p = params[1]
|
||||||
if type(p) ~= "number" then
|
if type(p) ~= "number" then
|
||||||
@ -217,7 +274,15 @@ s = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
tostring = function(params)
|
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,
|
end,
|
||||||
|
|
||||||
print = function(params, faden)
|
print = function(params, faden)
|
||||||
@ -259,4 +324,20 @@ for i = 1,#to_math_fcts do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local abbreviations = {
|
||||||
|
mov = ":=",
|
||||||
|
add = "+",
|
||||||
|
sub = "-",
|
||||||
|
mul = "*",
|
||||||
|
div = "/",
|
||||||
|
inc = "++",
|
||||||
|
dec = "--",
|
||||||
|
neg = "!",
|
||||||
|
less = "<",
|
||||||
|
equal = "==",
|
||||||
|
jmp = "@",
|
||||||
|
usleep = "...",
|
||||||
|
}
|
||||||
|
-- TODO set metatable
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
@ -13,13 +13,19 @@ local types = {
|
|||||||
|
|
||||||
local instr = {
|
local instr = {
|
||||||
{"mov", "<v to>, <e from>", "Copies from into to."},
|
{"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."},
|
{"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", "<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"},
|
{"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", "<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)"},
|
{"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", "<vn num>", "num = -num"},
|
||||||
{"neg", "<vb var>", "var = not var"},
|
{"neg", "<vb var>", "var = not var"},
|
||||||
{"neg", "<vs str>", "str = str:rev()"},
|
{"neg", "<vs str>", "str = str:rev()"},
|
||||||
@ -33,10 +39,13 @@ local instr = {
|
|||||||
{"equal", "<v a>, <e b>", "a = a == b"},
|
{"equal", "<v a>, <e b>", "a = a == b"},
|
||||||
{"less", "<vn a>, <n b>", "a = a < b; after executing, a is a bool"},
|
{"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"},
|
{"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"},
|
{"usleep", "<n t>", "aborts the program for at least floor(max(0, t)) ms"},
|
||||||
{"sleep", "<n t>", "executes usleep with t * 1000000 as argument"},
|
{"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"},
|
{"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)"},
|
{"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"},
|
{"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."},
|
{"flush", "", "Output the log, this should vary for every mod."},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user