split strictness to its own file

This commit is contained in:
Connor Olding 2018-04-02 15:28:00 +02:00
parent 545618c70b
commit 6a01f609a9
2 changed files with 26 additions and 23 deletions

View file

@ -1,26 +1,4 @@
-- hacks for FCEUX being dumb.
local _error = error
local _assert = assert
error = function(msg, level)
if level == nil then level = 1 end
print()
print(debug.traceback(msg, 1 + level):gsub("\n", "\r\n"))
_error(msg, level)
end
assert = function(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
-- be strict about globals.
local mt = getmetatable(_G)
if mt == nil then mt = {} setmetatable(_G, mt) 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
local globalize = require("strict")
-- configuration.

25
strict.lua Normal file
View file

@ -0,0 +1,25 @@
-- hacks for FCEUX being dumb.
local _error = error
local _assert = assert
error = function(msg, level)
if level == nil then level = 1 end
print()
print(debug.traceback(msg, 1 + level):gsub("\n", "\r\n"))
_error(msg, level)
end
assert = function(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
-- be strict about globals.
local mt = getmetatable(_G)
if mt == nil then mt = {} setmetatable(_G, mt) 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
return globalize