mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 15:23:43 +01:00
SaferLua extension for coroutine controllers to come...
This commit is contained in:
parent
ba051e45c5
commit
93b57cb780
@ -117,7 +117,7 @@ function safer_lua.run_loop(pos, elapsed, code, err_clbk)
|
|||||||
end
|
end
|
||||||
local res, err = pcall(code)
|
local res, err = pcall(code)
|
||||||
if calc_used_mem_size(env) > safer_lua.MaxTableSize then
|
if calc_used_mem_size(env) > safer_lua.MaxTableSize then
|
||||||
err_clbk("Memory limit exceeded")
|
err_clbk(pos, "Memory limit exceeded")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if not res then
|
if not res then
|
||||||
@ -131,12 +131,17 @@ end
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Endless/Coroutine controller
|
-- Endless/Coroutine controller
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
local function thread(code)
|
local function thread(pos, code, err_clbk)
|
||||||
while true do
|
while true do
|
||||||
code()
|
local res, err = pcall(code)
|
||||||
|
if not res then
|
||||||
|
err = err:gsub("%[string .+%]:", "loop() ")
|
||||||
|
err_clbk(pos, err)
|
||||||
|
return false
|
||||||
|
end
|
||||||
local env = getfenv(code)
|
local env = getfenv(code)
|
||||||
if calc_used_mem_size(env) > safer_lua.MaxTableSize then
|
if calc_used_mem_size(env) > safer_lua.MaxTableSize then
|
||||||
err_clbk("Memory limit exceeded")
|
err_clbk(pos, "Memory limit exceeded")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
@ -149,7 +154,7 @@ function safer_lua.co_create(pos, init, loop, environ, err_clbk)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function safer_lua.co_resume(pos, co, code, err_clbk)
|
function safer_lua.co_resume(pos, co, code, err_clbk)
|
||||||
local res, err = coroutine.resume(co, code)
|
local res, err = coroutine.resume(co, pos, code, err_clbk)
|
||||||
if not res then
|
if not res then
|
||||||
err = err:gsub("%[string .+%]:", "loop() ")
|
err = err:gsub("%[string .+%]:", "loop() ")
|
||||||
err_clbk(pos, err)
|
err_clbk(pos, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user