From 560329e5b04a10236d7bb5fdfd3fec840fdc7a1b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christophe=20Thi=C3=A9ry?= Date: Thu, 13 Oct 2011 13:44:21 +0200 Subject: [PATCH] Lua: more debugging info --- examples/lua/SimSplay/TODO | 2 +- examples/lua/SimSplay/splay_school.lua | 6 ++++-- examples/lua/state_cloner/duplicated_globals.lua | 2 +- src/bindings/lua/lua_state_cloner.c | 12 +++++++++--- src/bindings/lua/lua_utils.c | 2 +- src/bindings/lua/simgrid_lua.c | 10 ++++++++-- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/examples/lua/SimSplay/TODO b/examples/lua/SimSplay/TODO index 42dcb7f73b..4e9ad79e4c 100644 --- a/examples/lua/SimSplay/TODO +++ b/examples/lua/SimSplay/TODO @@ -11,7 +11,7 @@ Ideally, its usage would be: simsplay platform_file.{xml|lua} deployment_file.{xml|lua} splay_script.lua [simgrid_options...] I'm not sure about the format of the platform and deployment files yet. -We could accept both XML and Lua files, since their is a great Lua API to +We could accept both XML and Lua files, since there is a great Lua API to describe platforms, or only the XML ones. The simsplay executable (which is compiled C) would initialize SimGrid, create diff --git a/examples/lua/SimSplay/splay_school.lua b/examples/lua/SimSplay/splay_school.lua index 51cd58c40a..358c36f5d9 100644 --- a/examples/lua/SimSplay/splay_school.lua +++ b/examples/lua/SimSplay/splay_school.lua @@ -2,10 +2,10 @@ require("sim_splay") function SPLAYschool() log:print("My ip is: "..job.me.ip()) - for i = 1000,10000 do + for i = 1,200 do log:print(i) end - +--[[ events.sleep(5) if job.me.ip() == job.nodes[1].ip then @@ -13,6 +13,7 @@ function SPLAYschool() end events.sleep(5) os.exit() + --]] end function call_me(from) @@ -21,4 +22,5 @@ end events.thread("SPLAYschool") start.loop() +log:print("Simulation finished") diff --git a/examples/lua/state_cloner/duplicated_globals.lua b/examples/lua/state_cloner/duplicated_globals.lua index d4c2331290..516cc77200 100644 --- a/examples/lua/state_cloner/duplicated_globals.lua +++ b/examples/lua/state_cloner/duplicated_globals.lua @@ -22,7 +22,7 @@ function replace(...) please_dont_replace_me(...) end --- Show a hello message and prints the global string +-- Shows a hello message and prints the global string function please_dont_replace_me(...) simgrid.info("Hello from please_dont_replace_me(). I'm lucky, I still exist in this state.") diff --git a/src/bindings/lua/lua_state_cloner.c b/src/bindings/lua/lua_state_cloner.c index 4e35f184dd..c5abebbc97 100644 --- a/src/bindings/lua/lua_state_cloner.c +++ b/src/bindings/lua/lua_state_cloner.c @@ -13,7 +13,7 @@ #include #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua_state_cloner, lua, "Lua state management"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua_state_cloner, bindings, "Lua state management"); static void sglua_add_maestro_table(lua_State* L, int index, void* maestro_table_ptr); static void* sglua_get_maestro_table_ptr(lua_State* L, int index); @@ -409,7 +409,7 @@ static void sglua_copy_function(lua_State* src, lua_State* dst) { /* it's a Lua function: dump it from src */ s_sglua_buffer_t buffer; - buffer.capacity = 64; + buffer.capacity = 128; /* an empty function uses 77 bytes */ buffer.size = 0; buffer.data = xbt_new(char, buffer.capacity); @@ -417,6 +417,12 @@ static void sglua_copy_function(lua_State* src, lua_State* dst) { int error = lua_dump(src, sglua_memory_writer, &buffer); xbt_assert(!error, "Failed to dump the function from the source state: error %d", error); + XBT_DEBUG("Fonction dumped: %zu bytes", buffer.size); + + /* + fwrite(buffer.data, buffer.size, buffer.size, stderr); + fprintf(stderr, "\n"); + */ /* load the chunk into dst */ error = luaL_loadbuffer(dst, buffer.data, buffer.size, "(dumped function)"); @@ -609,7 +615,7 @@ lua_State* sglua_clone_maestro(void) { /* -- */ /* opening the standard libs is not necessary as they are - * be inherited like any global values */ + * inherited like any global values */ /* luaL_openlibs(L); */ XBT_DEBUG("New state created"); diff --git a/src/bindings/lua/lua_utils.c b/src/bindings/lua/lua_utils.c index 50b37eed97..84b8ca2799 100644 --- a/src/bindings/lua/lua_utils.c +++ b/src/bindings/lua/lua_utils.c @@ -10,7 +10,7 @@ #include "xbt.h" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua_utils, lua, "Lua helper functions"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua_utils, bindings, "Lua helper functions"); /** * @brief Returns a string representation of a value in the Lua stack. diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index 5fdd7c1618..09dd183acd 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -10,7 +10,7 @@ #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; @@ -314,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; } -- 2.20.1