From 1ffab1bf1ae10e5c2e1a95ca4f22797863af1cbd Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 20 Jul 2012 21:57:31 +0000 Subject: [PATCH] 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 --- polymer/eduke32/source/lunatic/defs.ilua | 21 ++++++++++++++++++--- polymer/eduke32/source/lunatic/test.elua | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index b83bc097e..bf423c8c5 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -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 diff --git a/polymer/eduke32/source/lunatic/test.elua b/polymer/eduke32/source/lunatic/test.elua index dd16efe9e..d5c09c462 100644 --- a/polymer/eduke32/source/lunatic/test.elua +++ b/polymer/eduke32/source/lunatic/test.elua @@ -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)