From: Christophe ThiƩry Date: Mon, 14 Nov 2011 14:10:41 +0000 (+0100) Subject: Lua: add a function simgrid.get_clock() X-Git-Tag: exp_20120216~298 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f45b6eaa01ced9382f2ec977555b66b55bc72fbf Lua: add a function simgrid.get_clock() --- diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index fa6ab955ef..f3367cb597 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -637,9 +637,9 @@ static const luaL_reg platf_functions[] = { * * - Argument 1 (string): name of the deployment file to load */ -static int launch_application(lua_State * L) -{ - const char *file = luaL_checkstring(L, 1); +static int launch_application(lua_State* L) { + + const char* file = luaL_checkstring(L, 1); MSG_function_register_default(run_lua_code); MSG_launch_application(file); return 0; @@ -652,9 +652,9 @@ static int launch_application(lua_State * L) * * - Argument 1 (string): name of the platform file to load */ -static int create_environment(lua_State * L) -{ - const char *file = luaL_checkstring(L, 1); +static int create_environment(lua_State* L) { + + const char* file = luaL_checkstring(L, 1); XBT_DEBUG("Loading environment file %s", file); MSG_create_environment(file); return 0; @@ -667,9 +667,9 @@ static int create_environment(lua_State * L) * * - Argument 1 (string): the text to print */ -static int debug(lua_State * L) -{ - const char *str = luaL_checkstring(L, 1); +static int debug(lua_State* L) { + + const char* str = luaL_checkstring(L, 1); XBT_DEBUG("%s", str); return 0; } @@ -681,9 +681,9 @@ static int debug(lua_State * L) * * - Argument 1 (string): the text to print */ -static int info(lua_State * L) -{ - const char *str = luaL_checkstring(L, 1); +static int info(lua_State* L) { + + const char* str = luaL_checkstring(L, 1); XBT_INFO("%s", str); return 0; } @@ -693,12 +693,25 @@ static int info(lua_State * L) * \param L a Lua state * \return number of values returned to Lua */ -static int run(lua_State * L) -{ +static int run(lua_State* L) { + MSG_main(); return 0; } +/** + * \brief Returns the current simulated time. + * \param L a Lua state + * \return number of values returned to Lua + * + * - Return value (number): the simulated time + */ +static int get_clock(lua_State* L) { + + lua_pushnumber(L, MSG_get_clock()); + return 1; +} + /** * \brief Cleans the simulation. * \param L a Lua state @@ -773,6 +786,7 @@ static const luaL_Reg simgrid_functions[] = { {"debug", debug}, {"info", info}, {"run", run}, + {"get_clock", get_clock}, /* short names */ {"platform", create_environment}, {"application", launch_application},