aboutsummaryrefslogtreecommitdiff
path: root/src/keeper.c
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2012-07-10 21:43:32 +0200
committerBenoit Germain <bnt.germain@gmail.com>2012-07-10 21:43:32 +0200
commit0373f863a9dbabbbe3e9aa74bea3e4b778f3a0cd (patch)
tree52dfb987d5ee12ef4668e875d19a70a6c77cebe1 /src/keeper.c
parent4468ec94e354a9f6d8d7ea2859afa757bb934617 (diff)
downloadlanes-3.1.5.tar.gz
lanes-3.1.5.tar.bz2
lanes-3.1.5.zip
one more step toward 5.2 compatibilityv3.1.5
* 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"
Diffstat (limited to 'src/keeper.c')
-rw-r--r--src/keeper.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/keeper.c b/src/keeper.c
index 6f5bd95..2404520 100644
--- a/src/keeper.c
+++ b/src/keeper.c
@@ -64,12 +64,6 @@ static struct s_Keeper *GKeepers = NULL;
64static int GNbKeepers = 0; 64static int GNbKeepers = 0;
65 65
66/* 66/*
67* Lua code for the keeper states (baked in)
68*/
69static char const keeper_chunk[]=
70#include "keeper.lch"
71
72/*
73* Initialize keeper states 67* Initialize keeper states
74* 68*
75* If there is a problem, return an error message (NULL for okay). 69* If there is a problem, return an error message (NULL for okay).
@@ -95,26 +89,31 @@ char const* init_keepers( int const _nbKeepers, lua_CFunction _on_state_create)
95 if (!K) 89 if (!K)
96 return "out of memory"; 90 return "out of memory";
97 91
92 STACK_CHECK( K)
98 // to see VM name in Decoda debugger 93 // to see VM name in Decoda debugger
99 lua_pushliteral( K, "Keeper #"); 94 lua_pushliteral( K, "Keeper #");
100 lua_pushinteger( K, i + 1); 95 lua_pushinteger( K, i + 1);
101 lua_concat( K, 2); 96 lua_concat( K, 2);
102 lua_setglobal( K, "decoda_name"); 97 lua_setglobal( K, "decoda_name");
103 98
104 // Read in the preloaded chunk (and run it) 99 // use package.loaders[2] to find keeper microcode
105 // 100 lua_getfield( K, LUA_GLOBALSINDEX, "package"); // package
106 if( luaL_loadbuffer( K, keeper_chunk, sizeof(keeper_chunk), "@keeper.lua")) 101 lua_getfield( K, -1, "loaders"); // package package.loaders
107 return "luaL_loadbuffer() failed"; // LUA_ERRMEM 102 lua_rawgeti( K, -1, 2); // package package.loaders package.loaders[2]
108 103 lua_pushliteral( K, "lanes-keeper"); // package package.loaders package.loaders[2] "lanes-keeper"
109 if( lua_pcall( K, 0 /*args*/, 0 /*results*/, 0 /*errfunc*/)) 104 STACK_MID( K, 4);
105 // first pcall loads lanes-keeper.lua, second one runs the chunk
106 if( lua_pcall( K, 1 /*args*/, 1 /*results*/, 0 /*errfunc*/) || lua_pcall( K, 0 /*args*/, 0 /*results*/, 0 /*errfunc*/))
110 { 107 {
111 // LUA_ERRRUN / LUA_ERRMEM / LUA_ERRERR 108 // LUA_ERRRUN / LUA_ERRMEM / LUA_ERRERR
112 // 109 //
113 char const* err = lua_tostring( K, -1); 110 char const* err = lua_tostring( K, -1);
114 assert( err); 111 assert( err);
115 return err; 112 return err;
116 } 113 } // package package.loaders
117 114 STACK_MID( K, 2);
115 lua_pop( K, 2);
116 STACK_END( K, 0)
118 MUTEX_INIT( &GKeepers[i].lock_); 117 MUTEX_INIT( &GKeepers[i].lock_);
119 GKeepers[i].L = K; 118 GKeepers[i].L = K;
120 //GKeepers[i].count = 0; 119 //GKeepers[i].count = 0;