Lunatic: override 'error' so that a string is always returned to C.

git-svn-id: https://svn.eduke32.com/eduke32@2838 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-07-20 21:57:31 +00:00
parent 55d474990f
commit 1ffab1bf1a
2 changed files with 22 additions and 3 deletions

View file

@ -542,8 +542,6 @@ end
local function errorf(level, fmt, ...)
local errmsg = string.format(fmt, ...)
error(errmsg, level+1)
-- XXX: error(nil) propagates to C!
end
local ERRLEV = 5
@ -638,6 +636,23 @@ local function our_module(modname)
oG.setfenv(2, M)
end
-- overridden 'error' that always passes a string to the base 'error'
local function our_error(errmsg, level)
if (type(errmsg) ~= "string") then
oG.error("error using 'error': error message must be a string", 2)
end
if (level) then
if (type(level) ~= "number") then
oG.error("error using 'error': error level must be a number", 2)
end
oG.error(errmsg, level==0 and 0 or level+1)
end
oG.error(errmsg, 2)
end
G_.require = our_require
G_.module = our_module
---G_.coroutine = coroutine
@ -657,7 +672,7 @@ G_.pcall = pcall
--jit
---G_.bit = bit
--package
G_.error = error
G_.error = our_error
--debug
--loadfile
--rawequal

View file

@ -241,3 +241,7 @@ local bittest = require "bittest"
bittest.sieve()
print('---=== END TEST SCRIPT ===---')
-- This will complain about wrong usage of 'error'. In particular,
-- the nil must not propagate to C!
error(nil)