@@ -112,7 +112,7 @@ char *lua_compile(msc_script **script, const char *filename, apr_pool_t *pool) {
112
112
dump .parts = apr_array_make (pool , 128 , sizeof (msc_script_part * ));
113
113
114
114
#if LUA_VERSION_NUM >= 503
115
- lua_dump (L , dump_writer , & dump , 1 );
115
+ lua_dump (L , dump_writer , & dump , 0 );
116
116
#else
117
117
lua_dump (L , dump_writer , & dump );
118
118
#endif
@@ -420,23 +420,32 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul
420
420
time_before = apr_time_now ();
421
421
422
422
#ifdef CACHE_LUA
423
+
423
424
L = msr -> L ;
424
425
rc = lua_gettop (L );
425
426
if (rc )
426
427
lua_pop (L , rc );
428
+
427
429
#else
430
+
428
431
/* Create new state. */
429
- #if LUA_VERSION_NUM > 501
432
+ #if LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503 || LUA_VERSION_NUM == 501
430
433
L = luaL_newstate ();
431
- #else
434
+ #elif LUA_VERSION_NUM == 500
432
435
L = lua_open ();
436
+ #else
437
+ #error We are only tested under Lua 5.0, 5.1, 5.2, or 5.3.
433
438
#endif
434
439
luaL_openlibs (L );
440
+
435
441
#endif
436
442
437
443
if (L == NULL )
438
444
return -1 ;
439
445
446
+ luaL_newmetatable (L , "luaL_msc" );
447
+ lua_newtable (L );
448
+
440
449
/* Associate msr with the state. */
441
450
lua_pushlightuserdata (L , (void * )msr );
442
451
lua_setglobal (L , "__msr" );
@@ -448,13 +457,16 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul
448
457
}
449
458
450
459
/* Register functions. */
451
- #if LUA_VERSION_NUM > 501
452
- luaL_setfuncs (L ,mylib ,0 );
453
- lua_setglobal (L ,"m" );
454
- #else
460
+ #if LUA_VERSION_NUM == 500 || LUA_VERSION_NUM == 501
455
461
luaL_register (L , "m" , mylib );
462
+ #elif LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503
463
+ luaL_setfuncs (L , mylib , 0 );
464
+ #else
465
+ #error We are only tested under Lua 5.0, 5.1, 5.2, or 5.3.
456
466
#endif
457
467
468
+ lua_setglobal (L , "m" );
469
+
458
470
rc = lua_restore (L , script );
459
471
if (rc ) {
460
472
* error_msg = apr_psprintf (msr -> mp , "Lua: Failed to restore script with %i." , rc );
0 commit comments