1
0
mirror of https://github.com/HybridDog/pdisc.git synced 2025-07-02 08:10:39 +02: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)