X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4610b103f5b664648c716031782165da1e6fbd41..6dc62256f5ada58d6f50cfac38f10d97b2a03cc2:/src/bindings/lua/simgrid_lua.c diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index 2dbb971a4b..9d878d57f0 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -8,8 +8,9 @@ #include "simgrid_lua.h" #include "lua_state_cloner.h" +#include "lua_utils.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(lua, "Lua Bindings"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua, bindings, "Lua Bindings"); static lua_State *lua_maestro_state; @@ -23,24 +24,26 @@ static lua_State *lua_maestro_state; static void register_c_functions(lua_State *L); -/* static void *my_checkudata (lua_State *L, int ud, const char *tname) { + + XBT_DEBUG("Checking the task: ud = %d", ud); + sglua_stack_dump("my_checkudata: ", L); void *p = lua_touserdata(L, ud); lua_getfield(L, LUA_REGISTRYINDEX, tname); const void* correct_mt = lua_topointer(L, -1); int has_mt = lua_getmetatable(L, ud); + XBT_DEBUG("Checking the task: has metatable ? %d", has_mt); const void* actual_mt = NULL; if (has_mt) { actual_mt = lua_topointer(L, -1); lua_pop(L, 1); } XBT_DEBUG("Checking the task's metatable: expected %p, found %p", correct_mt, actual_mt); - stack_dump("my_checkudata: ", L); + sglua_stack_dump("my_checkudata: ", L); if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2)) luaL_typerror(L, ud, tname); lua_pop(L, 2); return p; } -*/ /** * @brief Ensures that a userdata on the stack is a task @@ -52,6 +55,7 @@ static void *my_checkudata (lua_State *L, int ud, const char *tname) { static m_task_t checkTask(lua_State * L, int index) { m_task_t *pi, tk; + XBT_DEBUG("Lua task: %s", sglua_tostring(L, index)); luaL_checktype(L, index, LUA_TTABLE); lua_getfield(L, index, "__simgrid_task"); @@ -310,13 +314,19 @@ static int Host_at(lua_State * L) static int Host_self(lua_State * L) { + /* -- */ m_host_t host = MSG_host_self(); lua_newtable(L); - m_host_t *lua_host =(m_host_t *)lua_newuserdata(L,sizeof(m_host_t)); + /* table */ + m_host_t* lua_host = (m_host_t*) lua_newuserdata(L, sizeof(m_host_t)); + /* table ud */ *lua_host = host; luaL_getmetatable(L, HOST_MODULE_NAME); + /* table ud mt */ lua_setmetatable(L, -2); + /* table ud */ lua_setfield(L, -2, "__simgrid_host"); + /* table */ return 1; } @@ -522,7 +532,7 @@ static int run_lua_code(int argc, char **argv) { XBT_DEBUG("Run lua code %s", argv[0]); - lua_State *L = sglua_clone_state(lua_maestro_state); + lua_State *L = sglua_clone_maestro(); int res = 1; /* start the function */ @@ -606,7 +616,6 @@ static int msg_register_platform(lua_State * L) /* Tell Simgrid we dont wanna use its parser */ surf_parse = console_parse_platform; surf_parse_reset_callbacks(); - surf_config_models_setup(NULL); MSG_create_environment(NULL); return 0; } @@ -619,7 +628,6 @@ static int sd_register_platform(lua_State * L) { surf_parse = console_parse_platform_wsL07; surf_parse_reset_callbacks(); - surf_config_models_setup(NULL); SD_create_environment(NULL); return 0; } @@ -632,7 +640,6 @@ static int gras_register_platform(lua_State * L) /* Tell Simgrid we dont wanna use surf parser */ surf_parse = console_parse_platform; surf_parse_reset_callbacks(); - surf_config_models_setup(NULL); gras_create_environment(NULL); return 0; } @@ -738,13 +745,30 @@ int luaopen_simgrid(lua_State *L) /* initialize access to my tables by children Lua states */ lua_newtable(L); - lua_setfield(L, LUA_REGISTRYINDEX, "simgrid.visited_tables"); + lua_setfield(L, LUA_REGISTRYINDEX, "simgrid.maestro_tables"); register_c_functions(L); return 1; } +/** + * @brief Returns whether a Lua state is the maestro state. + * @param L a Lua state + * @return true if this is maestro + */ +int sglua_is_maestro(lua_State* L) { + return L == lua_maestro_state; +} + +/** + * @brief Returns the maestro state. + * @return true the maestro Lua state + */ +lua_State* sglua_get_maestro(void) { + return lua_maestro_state; +} + /** * Makes the appropriate Simgrid functions available to the Lua world. * @param L a Lua world