From fc23045675f6c9fb4bf1f709f8f3ae88a759f6a2 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Tue, 29 May 2012 20:01:58 +0000 Subject: [PATCH] Lunatic: fix one stack index, comment on a problem with ffi.C access. git-svn-id: https://svn.eduke32.com/eduke32@2710 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/defs.ilua | 9 +++++---- polymer/eduke32/source/lunatic/lunatic.c | 2 +- polymer/eduke32/source/lunatic/test.elua | 8 +++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 175d237e9..72557e8ef 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -452,7 +452,7 @@ local function printkv(label, table) print('----------') end -printkv('_G AFTER SETFENV', _G) +--printkv('_G AFTER SETFENV', _G) ---=== Restricted access to C variables from Lunatic ===--- @@ -469,6 +469,7 @@ local tmpmt = { } oG.setmetatable(det, tmpmt) +-- XXX: this is incorrect -- ffi.C also contains C library functions, etc. -- GLOBAL gv: provides access to C global *scalars* gv = { -- all non-scalars need to be explicitly listed @@ -486,8 +487,8 @@ gv = { actor = det, ud = det, - luaJIT_BC_con_lang, - luaJIT_BC_lunacon, + luaJIT_BC_con_lang = det, + luaJIT_BC_lunacon = det, } local tmpmt = { __index = ffiC, @@ -740,7 +741,7 @@ DBG_.loadGamevarsString = loadGamevarsString ---=== Finishing environment setup ===--- -printkv('_G AFTER DECLS', _G) +--printkv('_G AFTER DECLS', _G) -- PiL 14.2 continued diff --git a/polymer/eduke32/source/lunatic/lunatic.c b/polymer/eduke32/source/lunatic/lunatic.c index 8adc22a2b..cebcddd3c 100644 --- a/polymer/eduke32/source/lunatic/lunatic.c +++ b/polymer/eduke32/source/lunatic/lunatic.c @@ -111,7 +111,7 @@ int32_t El_RunOnce(El_State *estate, const char *fn) if (i == LUA_ERRSYNTAX) { - OSD_Printf("state \"%s\" syntax error: %s\n", estate->name, lua_tostring(estate->L, 1)); // get err msg + OSD_Printf("state \"%s\" syntax error: %s\n", estate->name, lua_tostring(estate->L, -1)); // get err msg lua_pop(estate->L, 1); return 3; } diff --git a/polymer/eduke32/source/lunatic/test.elua b/polymer/eduke32/source/lunatic/test.elua index a6915d4cc..22a7df2f2 100644 --- a/polymer/eduke32/source/lunatic/test.elua +++ b/polymer/eduke32/source/lunatic/test.elua @@ -84,7 +84,7 @@ if (vol==1 and lev==8) then end --]] -DBG_.printkv('_G in test.elua', _G) +--DBG_.printkv('_G in test.elua', _G) checkfail('print(sprite[100000].ceilingpal)') -- oob read access checkfail('setmetatable(sprite, {})') -- set metatable forbidden @@ -102,6 +102,12 @@ checkfail("new_global = 345") -- we should declare globals checkfail('gv.CEILING = 3') -- can't redefine constants in 'gv' checkfail('string.dump(setevent)') -- string.dump is unavailable +-- This is problematic, even though pretty much every access will yield a +-- "missing declaration" error. +-- See http://luajit.org/ext_ffi_api.html#ffi_C about what stuff ffi.C contains. +checkfail('gv.luaJIT_setmode(nil, 0, 0)') + setevent(gv.EVENT_JUMP, function() print("jump!") end) + print('---=== END TEST SCRIPT ===---')