1
0
mirror of https://github.com/HybridDog/pdisc.git synced 2024-11-15 14:50:39 +01:00

Add copytable instruction

This commit is contained in:
Hybrid Dog 2017-04-13 20:12:02 +02:00
parent c821cafc14
commit a1d7028b3e
2 changed files with 25 additions and 0 deletions

View File

@ -22,6 +22,30 @@ s = {
return true, {p, p ~= nil}
end,
copytable = function(params, thread)
if type(params[1]) ~= "string"
or type(params[2]) ~= "string" then
return false, "two strings expected"
end
local fromprefix = params[2] .. "."
local toprefix = params[1] .. "."
if fromprefix == toprefix then
return false, "origin and target table names must be different"
end
local tocopy = {}
local frmln = #fromprefix
for name,v in pairs(thread.vars) do
if name:sub(1, frmln) == fromprefix then
tocopy[#tocopy+1] = name:sub(frmln+1)
end
end
for i = 1,#tocopy do
local field = tocopy[i]
thread.vars[toprefix .. field] = thread.vars[fromprefix .. field]
end
return true
end,
add = function(params, faden)
local p1,p2 = unpack(params)
local t1 = type(p1)

View File

@ -15,6 +15,7 @@ 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."},
{"copytable", "<s target>, <s origin>", "Copies ${origin}.* to ${target}.*."},
{"add", "<vn to>, <n from>", "to += 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"},