controller instance bug fix

for loops added
This commit is contained in:
Joachim Stolberg 2018-06-30 16:04:55 +02:00
parent 44c5285f28
commit b7d58147fe
3 changed files with 36 additions and 5 deletions

@ -28,6 +28,7 @@ safer_lua.DataStructHelp = [[
a.remove(3) --> {1,8,4,7,6}
a.insert(1, "hello") --> {"hello",1,8,4,7,6}
a.size() --> function returns 6
a.next() --> for loop iterator function
Unlike arrays, which are indexed by a range of numbers,
'stores' are indexed by keys:
@ -38,6 +39,7 @@ safer_lua.DataStructHelp = [[
s.set(0, "hello") --> {val = 12, [0] = "hello"}
s.del("val") --> {[0] = "hello"}
s.size() --> function returns 1
s.next() --> for loop iterator function
A 'set' is an unordered collection with no duplicate
elements.
@ -49,6 +51,7 @@ safer_lua.DataStructHelp = [[
s.has("Susi") --> function returns `true`
s.has("Mike") --> function returns `false`
s.size() --> function returns 2
s.next() --> for loop iterator function
]]
local function var_count(v)
@ -123,6 +126,13 @@ function safer_lua.Store()
return Size
end
new_t.next = function(t)
local n = nil
return function ()
n = next(Data, n)
if n then return n, Data[n] end
end
end
new_t.__dump = function()
-- remove the not serializable meta data
return {Type = "Store", Size = Size, MemSize = MemSize, Data = Data}
@ -196,6 +206,15 @@ function safer_lua.Array(...)
return #Data
end
new_t.next = function(t)
local i = 0
local n = #Data
return function ()
i = i + 1
if i <= n then return i, Data[i] end
end
end
new_t.__dump = function()
-- remove the not serializable meta data
return {Type = "Array", MemSize = MemSize, Data = Data}
@ -257,6 +276,16 @@ function safer_lua.Set(...)
return Size
end
new_t.next = function(t)
local i = 0
local n = nil
return function ()
i = i + 1
n = next(Data, n)
if n then return i, n end
end
end
new_t.__dump = function()
-- remove the not serializable meta data
return {Type = "Set", Size = Size, MemSize = MemSize, Data = Data}

@ -84,7 +84,7 @@ function safer_lua.init(pos, init, loop, environ, err_clbk)
end
local code = compile(pos, init, "init() ", err_clbk)
if code then
local env = BASE_ENV
local env = table.copy(BASE_ENV)
env.S = {}
env.S = map(env.S, environ)
setfenv(code, env)

@ -78,7 +78,6 @@ local InvalidKeywords = {
["break"] = true,
["until"] = true,
["for"] = true,
["do"] = true,
["function"] = true,
["_G"] = true,
["__load"] = true,
@ -95,12 +94,15 @@ function safer_lua:check(text, label, err_clbk)
local lToken = self:scanner(text)
local lineno = 0
local errno = 0
for _,token in ipairs(lToken) do
for idx,token in ipairs(lToken) do
if type(token) == "number" then
lineno = token
elseif InvalidKeywords[token] then
err_clbk(label..lineno..": Invalid keyword '"..token.."'")
errno = errno + 1
if token ~= "for" or lToken[idx + 3] ~= "in" or
lToken[idx + 5] ~= "next" then -- invalid for statement?
err_clbk(label..lineno..": Invalid keyword '"..token.."'")
errno = errno + 1
end
elseif InvalidChars[token] then
err_clbk(label..lineno..": Invalid character '"..token.."'")
errno = errno + 1