diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index ff42d35da..9f07729c3 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -1477,6 +1477,13 @@ local function our_require(modname, ...) --- Search user modules... + if (modname:find("[/\\]")) then + error("Module name must not contain directory separators", ERRLEV-1) + end + -- Instead, dots are translated to directory separators. For EDuke32's + -- virtual file system, this is always a forward slash. + modname = modname:gsub("%.", "/") + local omod = package_loaded[modname] if (omod ~= nil) then if (omod==false) then @@ -2038,8 +2045,16 @@ end if (not g_firstRun) then local i=0 while (ffiC.g_elModules[i] ~= nil) do - local modname = ffi.string(ffiC.g_elModules[i]) - our_require((modname:gsub("%.lua$",""))) + -- Get the module name and strip the trailing extension. + local modname = ffi.string(ffiC.g_elModules[i]):gsub("%.lua$","") + + if (modname:find("%.")) then + -- Because they will be replaced by dirseps in our_require(). + error("Dots are not permitted in module names", 0) + end + -- Allow forward slashes in module names from the cmdline. + our_require((modname:gsub("%.lua$",""):gsub("/","."))) + i = i+1 end end diff --git a/polymer/eduke32/source/lunatic/test.elua b/polymer/eduke32/source/lunatic/test.elua index 1f4efb804..658f23423 100644 --- a/polymer/eduke32/source/lunatic/test.elua +++ b/polymer/eduke32/source/lunatic/test.elua @@ -180,7 +180,7 @@ checkfail('local spr = sprite[0]; local x=spr+1', "attempt to perform arithmetic checkfail('gameactor(1680, 0)', "invalid last argument to gameactor: must be a function") -checkfail("do local bt=require'test/test_bitar'; bt.QWE=1; end", "modifying module table forbidden") +checkfail("do local bt=require'test.test_bitar'; bt.QWE=1; end", "modifying module table forbidden") -- the cdata returned by player[] can't be made into a pointer! checkfail("do local pl=player[0]; i=pl[1]; end") checkfail("do local ud=gv.ud.camerasprite; end", "access forbidden") -- test for proper decl() @@ -470,11 +470,11 @@ end) printf("EVENT_INIT = %d", gv.EVENT_INIT) -- tests default defines -local bittest = require "test/test_bitar" +local bittest = require "test.test_bitar" bittest.sieve() -require("test/test_geom") -require("test/test_rotspr") +require("test.test_geom") +require("test.test_rotspr") do -- Test ksin vs. sinb