LDDestroier

machina api test

Jan 3rd, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. machina = {}
  2.  
  3. local funclist = {}
  4.  
  5. machina.setList = function(...)
  6.     local yarr = table.pack(...)
  7.     local errorlist = {}
  8.     for a = 1, #yarr do
  9.         if type(yarr[a]) ~= "function" then
  10.             errorlist[#errorlist+1] = a
  11.         end
  12.     end
  13.     if #errorlist > 0 then
  14.         local errormsg = "bad argument types: "
  15.         for a = 1, #errorlist do
  16.             errormsg = errormsg.."arg"..a.." is "..type(yarr[errorlist[a]])
  17.             if a < #errorlist then
  18.                 errormsg = errormsg..", "
  19.             else
  20.                 errormsg = errormsg.."."
  21.             end
  22.         end
  23.     else
  24.         funclist = table.pack(...)
  25.         return true
  26.     end
  27. end
  28.  
  29. machina.startLoop = function()
  30.     local golly_G = setmetatable({}, {__index=(_ENV or getfenv())})
  31.     local funcpos
  32.     golly_G.coroutine.yield = function(check)
  33.         if funcpos < #funclist then
  34.             funcpos = funcpos + 1
  35.             local func = funclist[a]
  36.             func = setfenv(func, golly_G)
  37.             func()
  38.         end
  39.         return table.unpack(evt)
  40.     end
  41.     while true do
  42.         funcpos = 1
  43.         local evt = {os.pullEvent()}
  44.         local func = funclist[a]
  45.         func = setfenv(func, golly_G)
  46.         local output = {pcall( function() return func() end )}
  47.     end
  48. end
Add Comment
Please, Sign In to add comment