瀏覽代碼

reduce possibility of errors in love code when overwriting built-in lua APIs

Sasha Szpakowski 3 月之前
父節點
當前提交
de5495bb03

+ 1 - 1
src/modules/graphics/wrap_Graphics.lua

@@ -24,7 +24,7 @@ misrepresented as being the original software.
 
 local table_concat = table.concat
 local ipairs = ipairs
-local pcall = pcall
+local pcall, type, error = pcall, type, error
 local graphics = love.graphics
 
 function graphics.newVideo(file, settings)

+ 3 - 1
src/modules/love/boot.lua

@@ -441,6 +441,8 @@ function love.init()
 	end
 end
 
+local xpcall = xpcall
+local coroutine_yield = coroutine.yield
 local print, debug, tostring = print, debug, tostring
 
 local function error_printer(msg, layer)
@@ -498,7 +500,7 @@ return function()
 		end
 		local _, retval, restartvalue = xpcall(func, deferErrhand)
 		if retval then return retval, restartvalue end
-		coroutine.yield()
+		coroutine_yield()
 	end
 
 	return 1

+ 1 - 0
src/modules/love/callbacks.lua

@@ -202,6 +202,7 @@ function love.run()
 	end
 end
 
+local pcall, table = pcall, table
 local debug, print, tostring, error = debug, print, tostring, error
 
 function love.threaderror(t, err)

+ 1 - 1
src/modules/sound/wrap_SoundData.lua

@@ -34,7 +34,7 @@ end
 local status, ffi = pcall(require, "ffi")
 if not status then return end
 
-local tonumber, assert, error = tonumber, assert, error
+local tonumber, assert, error, type = tonumber, assert, error, type
 local floor = math.floor
 
 local float = ffi.typeof("float")