Add first draft cart loader

This commit is contained in:
Robert Miles 2018-07-24 04:16:11 -04:00
parent 9f40b004f5
commit f881be51e4
1 changed files with 17 additions and 0 deletions

View File

@ -2,6 +2,14 @@ local Cart = {
code = function() return function() end, function() end end
}
local function split(str)
local lines = {}
for s in str:gmatch("[^\r\n]+") do
table.insert(lines, s)
end
return lines
end
function Cart:new(o)
o = o or {}
setmetatable(o,self)
@ -12,5 +20,14 @@ end
function Cart:loadCart(s)
local ret = self:new()
if not love.filesystem.getInfo(s,"file") then return ret end
local code = ""
for _,s in pairs(split(love.filesystem.read(s))) do
code = code..s.."\n"
end
code = "return (_update or function() end),(_draw or function() end)\n"
local ok,err = pcall(loadstring,code)
if not ok then error(err) end
sandbox(err)
ret.code = err
return ret
end