Skip to content

Commit

Permalink
feat: add loadstring error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ExponentialWorkload authored Jan 29, 2023
1 parent 6f83eca commit a381264
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ if Window and PROTOSMASHER_LOADED then
getgenv().get_script_function = nil
end

local loadstring = loadstring or load;
local loadstringWarnOnError = function(content, chunkName)
local chunk, err = loadstring(content, chunkName);
if type(chunk) ~= 'function' then warn('Error Compiling \''..asset..'.lua\'\n-> Error: '..tostring(err or 'Unknown - Chunk wasn\'t function')..'\nFurther errors may be caused by this.')end
return chunk, err
end

local globalMethods = {
checkCaller = checkcaller,
newCClosure = newcclosure,
Expand Down Expand Up @@ -238,12 +245,12 @@ if readFile and writeFile then
end
end

assets = { loadstring(content, asset .. '.lua')() }
assets = { loadstringWarnOnError(content, asset .. '.lua')() }
else
assets = { loadstring(game:HttpGetAsync("https://raw.githubusercontent.com/" .. user .. "/Hydroxide/" .. branch .. '/' .. asset .. ".lua"), asset .. '.lua')() }
assets = { loadstringWarnOnError(game:HttpGetAsync("https://raw.githubusercontent.com/" .. user .. "/Hydroxide/" .. branch .. '/' .. asset .. ".lua"), asset .. '.lua')() }
end
else
assets = { loadstring(readFile("hydroxide/" .. asset .. ".lua"), asset .. '.lua')() }
assets = { loadstringWarnOnError(readFile("hydroxide/" .. asset .. ".lua"), '(oh/)' .. asset .. '.lua')() }
end

importCache[asset] = assets
Expand All @@ -270,10 +277,9 @@ if readFile and writeFile then
else
content = result
end

assets = { loadstring(content, asset .. '.lua')() }
assets = { loadstringWarnOnError(content, asset .. '.lua')() }
else
assets = { loadstring(readFile("hydroxide/" .. asset .. ".lua"), asset .. '.lua')() }
assets = { loadstringWarnOnError(readFile("hydroxide/" .. asset .. ".lua"), '(oh/)' .. asset .. '.lua')() }
end

importCache[asset] = assets
Expand Down

0 comments on commit a381264

Please sign in to comment.