From 0373f863a9dbabbbe3e9aa74bea3e4b778f3a0cd Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 10 Jul 2012 21:43:32 +0200 Subject: one more step toward 5.2 compatibility * lua51-lanes renamed lanes.core * keeper state microcode is no longer embedded inside lanes.core, but located and loaded with package.loaders[2] * changed rockspec build type from "make" to "builtin" --- src/keeper.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/keeper.c') diff --git a/src/keeper.c b/src/keeper.c index 6f5bd95..2404520 100644 --- a/src/keeper.c +++ b/src/keeper.c @@ -63,12 +63,6 @@ static struct s_Keeper *GKeepers = NULL; static int GNbKeepers = 0; -/* -* Lua code for the keeper states (baked in) -*/ -static char const keeper_chunk[]= -#include "keeper.lch" - /* * Initialize keeper states * @@ -95,26 +89,31 @@ char const* init_keepers( int const _nbKeepers, lua_CFunction _on_state_create) if (!K) return "out of memory"; + STACK_CHECK( K) // to see VM name in Decoda debugger lua_pushliteral( K, "Keeper #"); lua_pushinteger( K, i + 1); lua_concat( K, 2); lua_setglobal( K, "decoda_name"); - // Read in the preloaded chunk (and run it) - // - if( luaL_loadbuffer( K, keeper_chunk, sizeof(keeper_chunk), "@keeper.lua")) - return "luaL_loadbuffer() failed"; // LUA_ERRMEM - - if( lua_pcall( K, 0 /*args*/, 0 /*results*/, 0 /*errfunc*/)) + // use package.loaders[2] to find keeper microcode + lua_getfield( K, LUA_GLOBALSINDEX, "package"); // package + lua_getfield( K, -1, "loaders"); // package package.loaders + lua_rawgeti( K, -1, 2); // package package.loaders package.loaders[2] + lua_pushliteral( K, "lanes-keeper"); // package package.loaders package.loaders[2] "lanes-keeper" + STACK_MID( K, 4); + // first pcall loads lanes-keeper.lua, second one runs the chunk + if( lua_pcall( K, 1 /*args*/, 1 /*results*/, 0 /*errfunc*/) || lua_pcall( K, 0 /*args*/, 0 /*results*/, 0 /*errfunc*/)) { // LUA_ERRRUN / LUA_ERRMEM / LUA_ERRERR // char const* err = lua_tostring( K, -1); assert( err); return err; - } - + } // package package.loaders + STACK_MID( K, 2); + lua_pop( K, 2); + STACK_END( K, 0) MUTEX_INIT( &GKeepers[i].lock_); GKeepers[i].L = K; //GKeepers[i].count = 0; -- cgit v1.2.3-55-g6feb