function love.load()
function customParse(parseString, parseCharacter)
local parseResults = {}
local stringCycle = ""
for i = 1, #parseString do
local c = parseString:sub(i,i)
if c == parseCharacter then
if stringCycle == "" then
else
table.insert(parseResults, stringCycle)
stringCycle = ""
end
else
stringCycle = stringCycle .. c
end
if i == #parseString and c ~= parseCharacter then
table.insert(parseResults, stringCycle)
stringCycle = ""
end
end
return parseResults
end
tAPIsLoading = {}
function loadAPI(_sPath)
customParsedPath = customParse(_sPath, "/")
local sName = customParsedPath[#customParsedPath]
if tAPIsLoading[sName] == true then
error("API " ..sName.." is already being loaded")
return false
end
tAPIsLoading[sName] = true
local tEnv = {}
setmetatable(tEnv, {__index = _G})
local fnAPI, err = loadfile(_sPath, tEnv)
if fnAPI then
local ok, err = pcall(fnAPI)
if not ok then
error(err)
tAPIsLoading[sName] = nil
return false
end
else
error(err)
tAPIsLoading[sName] = nil
return false
end
local tAPI = {}
for k, v in pairs(tEnv) do
if k ~= "_ENV" then
tAPI[k] = v
end
end
_G[sName] = tAPI
tAPIsLoading[sName] = nil
return true
end
loadAPI("test.lua")
end
function love.draw()
foo()
end
However I get the following message:
"Error: main.lua:37: bad argument #2 to 'loadfile' (string expected, got table)
[c]: main.lua:37: in function 'loadfile'
main.lua:37: in function 'loadAPI'
main.lua:63: in function 'load'
[C]: in function 'xpcall'"