hacks
This commit is contained in:
parent
693eeb991e
commit
f7bee50d12
42
main.lua
42
main.lua
|
@ -1,24 +1,28 @@
|
||||||
|
-- hacks for FCEUX being dumb.
|
||||||
|
local _error = error
|
||||||
|
local _assert = assert
|
||||||
|
local function error_(msg, level)
|
||||||
|
if level == nil then level = 1 end
|
||||||
|
print()
|
||||||
|
print(debug.traceback(msg, 1 + level):gsub("\n", "\r\n"))
|
||||||
|
_error(msg, level)
|
||||||
|
end
|
||||||
|
local function assert_(cond, msg)
|
||||||
|
if cond then return cond end
|
||||||
|
msg = msg or "nondescript"
|
||||||
|
print()
|
||||||
|
print(debug.traceback(msg, 2):gsub("\n", "\r\n"))
|
||||||
|
_error("assertion failed!")
|
||||||
|
end
|
||||||
|
rawset(_G, 'error', error_)
|
||||||
|
rawset(_G, 'assert', assert_)
|
||||||
|
|
||||||
-- be strict about globals.
|
-- be strict about globals.
|
||||||
|
|
||||||
local mt = getmetatable(_G)
|
local mt = getmetatable(_G)
|
||||||
if mt == nil then
|
if mt == nil then mt = {} setmetatable(_G, mt) end
|
||||||
mt = {}
|
function mt.__newindex(t, n, v) error("cannot assign undeclared global '" .. tostring(n) .. "'", 2) end
|
||||||
setmetatable(_G, mt)
|
function mt.__index(t, n) error("cannot use undeclared global '" .. tostring(n) .. "'", 2) end
|
||||||
end
|
local function globalize(t) for k, v in pairs(t) do rawset(_G, k, v) end end
|
||||||
|
|
||||||
function mt.__newindex(t, n, v)
|
|
||||||
error("cannot assign undeclared global '" .. tostring(n) .. "'", 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
function mt.__index(t, n)
|
|
||||||
error("cannot use undeclared global '" .. tostring(n) .. "'", 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function globalize(t)
|
|
||||||
for k, v in pairs(t) do
|
|
||||||
rawset(_G, k, v)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- configuration and globals.
|
-- configuration and globals.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user