1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 /* SimGrid Lua bindings */
9 #include "simgrid_lua.h"
10 #include "lua_state_cloner.h"
11 #include "lua_utils.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua, bindings, "Lua Bindings");
15 #define TASK_MODULE_NAME "simgrid.task"
16 #define HOST_MODULE_NAME "simgrid.host"
18 #define LINK_MODULE_NAME "simgrid.link"
19 #define ROUTE_MODULE_NAME "simgrid.route"
20 #define PLATF_MODULE_NAME "simgrid.platf"
22 static lua_State* sglua_maestro_state;
24 int luaopen_simgrid(lua_State *L);
25 static void register_c_functions(lua_State *L);
26 static int run_lua_code(int argc, char **argv);
30 * \brief Like luaL_checkudata, with additional debug logs.
32 * This function is for debugging purposes only.
34 * \param L a lua state
35 * \param ud index of the userdata to check in the stack
36 * \param tname key of the metatable of this userdata in the registry
38 static void* my_checkudata(lua_State* L, int ud, const char* tname)
40 XBT_DEBUG("Checking the userdata: ud = %d", ud);
41 sglua_stack_dump("my_checkudata: ", L);
42 void* p = lua_touserdata(L, ud);
43 lua_getfield(L, LUA_REGISTRYINDEX, tname);
44 const void* correct_mt = lua_topointer(L, -1);
46 int has_mt = lua_getmetatable(L, ud);
47 XBT_DEBUG("Checking the userdata: has metatable ? %d", has_mt);
48 const void* actual_mt = NULL;
50 actual_mt = lua_topointer(L, -1);
53 XBT_DEBUG("Checking the task's metatable: expected %p, found %p", correct_mt, actual_mt);
54 sglua_stack_dump("my_checkudata: ", L);
56 if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2))
57 luaL_typerror(L, ud, tname);
62 /* ********************************************************************************* */
63 /* simgrid.task API */
64 /* ********************************************************************************* */
67 * \brief Ensures that a value in the stack is a valid task and returns it.
68 * \param L a Lua state
69 * \param index an index in the Lua stack
70 * \return the C task corresponding to this Lua task
72 static m_task_t sglua_checktask(lua_State* L, int index)
74 sglua_stack_dump("check task: ", L);
75 luaL_checktype(L, index, LUA_TTABLE);
77 lua_getfield(L, index, "__simgrid_task");
78 /* ... task ... ctask */
79 m_task_t task = *((m_task_t*) luaL_checkudata(L, -1, TASK_MODULE_NAME));
84 luaL_error(L, "This task was sent to someone else, you cannot access it anymore");
91 * \brief Creates a new task and leaves it onto the stack.
92 * \param L a Lua state
93 * \return number of values returned to Lua
95 * - Argument 1 (string): name of the task
96 * - Argument 2 (number): computation size
97 * - Argument 3 (number): communication size
98 * - Return value (task): the task created
100 static int l_task_new(lua_State* L)
102 XBT_DEBUG("Task new");
103 const char* name = luaL_checkstring(L, 1);
104 int comp_size = luaL_checkint(L, 2);
105 int msg_size = luaL_checkint(L, 3);
109 m_task_t msg_task = MSG_task_create(name, comp_size, msg_size, NULL);
113 m_task_t* lua_task = (m_task_t*) lua_newuserdata(L, sizeof(m_task_t));
115 *lua_task = msg_task;
116 luaL_getmetatable(L, TASK_MODULE_NAME);
118 lua_setmetatable(L, -2);
120 lua_setfield(L, -2, "__simgrid_task");
126 * \brief Returns the name of a task.
127 * \param L a Lua state
128 * \return number of values returned to Lua
130 * - Argument 1 (task): a task
131 * - Return value (string): name of the task
133 static int l_task_get_name(lua_State* L)
135 m_task_t task = sglua_checktask(L, 1);
136 lua_pushstring(L, MSG_task_get_name(task));
141 * \brief Returns the computation duration of a task.
142 * \param L a Lua state
143 * \return number of values returned to Lua
145 * - Argument 1 (task): a task
146 * - Return value (number): computation duration of this task
148 static int l_task_computation_duration(lua_State* L)
150 m_task_t task = sglua_checktask(L, 1);
151 lua_pushnumber(L, MSG_task_get_compute_duration(task));
156 * \brief Executes a task.
157 * \param L a Lua state
158 * \return number of values returned to Lua
160 * - Argument 1 (task): the task to execute
161 * - Return value (number): error code
163 static int l_task_execute(lua_State* L)
165 m_task_t task = sglua_checktask(L, 1);
166 int res = MSG_task_execute(task);
167 lua_pushnumber(L, res);
172 * \brief Sends a task to a mailbox and waits for its completion.
173 * \param L a Lua state
174 * \return number of values returned to Lua
176 * - Argument 1 (task): the task to send
177 * - Argument 2 (string): mailbox
179 static int l_task_send(lua_State* L)
181 m_task_t task = sglua_checktask(L, 1);
182 const char* mailbox = luaL_checkstring(L, 2);
186 /* copy my stack into the task, so that the receiver can copy the lua task */
187 MSG_task_set_data(task, L);
188 MSG_error_t res = MSG_task_send(task, mailbox);
189 while (MSG_task_get_data(task) != NULL) {
190 /* don't mess up with my stack: the receiver didn't copy the data yet */
191 MSG_process_sleep(0);
195 /* the receiver is the owner of the task and may destroy it:
196 * remove the C task on my side so that I don't garbage collect it */
197 lua_getfield(L, 1, "__simgrid_task");
199 m_task_t* udata = (m_task_t*) luaL_checkudata(L, -1, TASK_MODULE_NAME);
207 XBT_DEBUG("MSG_task_send failed : Timeout");
209 case MSG_TRANSFER_FAILURE:
210 XBT_DEBUG("MSG_task_send failed : Transfer Failure");
212 case MSG_HOST_FAILURE:
213 XBT_DEBUG("MSG_task_send failed : Host Failure ");
217 ("MSG_task_send failed : Unexpected error , please report this bug");
225 * \brief Receives a task or fails after a timeout.
226 * \param L a Lua state
227 * \return number of values returned to Lua
229 * - Argument 1 (string): mailbox
230 * - Argument 2 (number): timeout
231 * - Return value (task/nil): the task received or nil if the communication
234 static int l_task_recv_with_timeout(lua_State *L)
236 m_task_t task = NULL;
237 const char* mailbox = luaL_checkstring(L, 1);
238 int timeout = luaL_checknumber(L, 2);
239 /* mailbox timeout */
242 MSG_error_t res = MSG_task_receive_with_timeout(&task, mailbox, timeout);
245 /* copy the data directly from sender's stack */
246 lua_State* sender_stack = MSG_task_get_data(task);
247 sglua_copy_value(sender_stack, L);
249 MSG_task_set_data(task, NULL);
254 XBT_DEBUG("MSG_task_receive failed : Timeout");
256 case MSG_TRANSFER_FAILURE:
257 XBT_DEBUG("MSG_task_receive failed : Transfer Failure");
259 case MSG_HOST_FAILURE:
260 XBT_DEBUG("MSG_task_receive failed : Host Failure ");
263 XBT_ERROR("MSG_task_receive failed : Unexpected error , please report this bug");
274 * \brief Receives a task.
275 * \param L a Lua state
276 * \return number of values returned to Lua
278 * - Argument 1 (string): mailbox
279 * - Return value (task/nil): the task received or nil if the communication
282 static int l_task_recv(lua_State * L)
284 lua_pushnumber(L, -1.0);
285 return l_task_recv_with_timeout(L);
288 static const luaL_reg task_functions[] = {
290 {"name", l_task_get_name},
291 {"computation_duration", l_task_computation_duration},
292 {"execute", l_task_execute},
293 {"send", l_task_send},
294 {"recv", l_task_recv},
295 {"recv_timeout", l_task_recv_with_timeout},
300 * \brief Finalizes the userdata of a task.
301 * \param L a Lua state
302 * \return number of values returned to Lua
304 * - Argument 1 (userdata): a C task, possibly NULL if it was sent to another
307 static int l_task_gc(lua_State* L)
310 m_task_t task = *((m_task_t*) luaL_checkudata(L, 1, TASK_MODULE_NAME));
311 /* the task is NULL if I sent it to someone else */
313 MSG_task_destroy(task);
319 * \brief Returns a string representation of a C task.
320 * \param L a Lua state
321 * \return number of values returned to Lua
323 * - Argument 1 (userdata): a task
324 * - Return value (string): a string describing this task
326 static int l_task_tostring(lua_State* L)
328 m_task_t task = sglua_checktask(L, 1);
329 lua_pushfstring(L, "Task: %p", task);
333 static const luaL_reg task_meta[] = {
335 {"__tostring", l_task_tostring},
339 /* ********************************************************************************* */
340 /* simgrid.host API */
341 /* ********************************************************************************* */
344 * \brief Ensures that a value in the stack is a host and returns it.
345 * \param L a Lua state
346 * \param index an index in the Lua stack
347 * \return the C host corresponding to this Lua host
349 static m_host_t sglua_checkhost(lua_State * L, int index)
352 luaL_checktype(L, index, LUA_TTABLE);
353 lua_getfield(L, index, "__simgrid_host");
354 pi = (m_host_t *) luaL_checkudata(L, lua_gettop(L), HOST_MODULE_NAME);
356 luaL_typerror(L, index, HOST_MODULE_NAME);
359 luaL_error(L, "null Host");
365 * \brief Returns a host given its name.
366 * \param L a Lua state
367 * \return number of values returned to Lua
369 * - Argument 1 (string): name of a host
370 * - Return value (host): the corresponding host
372 static int l_host_get_by_name(lua_State * L)
374 const char *name = luaL_checkstring(L, 1);
375 XBT_DEBUG("Getting Host from name...");
376 m_host_t msg_host = MSG_get_host_by_name(name);
378 luaL_error(L, "null Host : MSG_get_host_by_name failed");
380 lua_newtable(L); /* create a table, put the userdata on top of it */
381 m_host_t *lua_host = (m_host_t *) lua_newuserdata(L, sizeof(m_host_t));
382 *lua_host = msg_host;
383 luaL_getmetatable(L, HOST_MODULE_NAME);
384 lua_setmetatable(L, -2);
385 lua_setfield(L, -2, "__simgrid_host"); /* put the userdata as field of the table */
386 /* remove the args from the stack */
392 * \brief Returns the name of a host.
393 * \param L a Lua state
394 * \return number of values returned to Lua
396 * - Argument 1 (host): a host
397 * - Return value (string): name of this host
399 static int l_host_get_name(lua_State * L)
401 m_host_t ht = sglua_checkhost(L, 1);
402 lua_pushstring(L, MSG_host_get_name(ht));
407 * \brief Returns the number of existing hosts.
408 * \param L a Lua state
409 * \return number of values returned to Lua
411 * - Return value (number): number of hosts
413 static int l_host_number(lua_State * L)
415 lua_pushnumber(L, MSG_get_host_number());
420 * \brief Returns the host given its index.
421 * \param L a Lua state
422 * \return number of values returned to Lua
424 * - Argument 1 (number): an index (1 is the first)
425 * - Return value (host): the host at this index
427 static int l_host_at(lua_State * L)
429 int index = luaL_checkinteger(L, 1);
430 m_host_t host = MSG_get_host_table()[index - 1]; // lua indexing start by 1 (lua[1] <=> C[0])
431 lua_newtable(L); /* create a table, put the userdata on top of it */
432 m_host_t *lua_host = (m_host_t *) lua_newuserdata(L, sizeof(m_host_t));
434 luaL_getmetatable(L, HOST_MODULE_NAME);
435 lua_setmetatable(L, -2);
436 lua_setfield(L, -2, "__simgrid_host"); /* put the userdata as field of the table */
441 * \brief Returns the host where the current process is located.
442 * \param L a Lua state
443 * \return number of values returned to Lua
445 * - Return value (host): the current host
447 static int l_host_self(lua_State * L)
450 m_host_t host = MSG_host_self();
453 m_host_t* lua_host = (m_host_t*) lua_newuserdata(L, sizeof(m_host_t));
456 luaL_getmetatable(L, HOST_MODULE_NAME);
458 lua_setmetatable(L, -2);
460 lua_setfield(L, -2, "__simgrid_host");
466 * \brief Returns the value of a host property.
467 * \param L a Lua state
468 * \return number of values returned to Lua
470 * - Argument 1 (host): a host
471 * - Argument 2 (string): name of the property to get
472 * - Return value (string): the value of this property
474 static int l_host_get_property_value(lua_State * L)
476 m_host_t ht = sglua_checkhost(L, 1);
477 const char *prop = luaL_checkstring(L, 2);
478 lua_pushstring(L,MSG_host_get_property_value(ht,prop));
483 * \brief Makes the current process sleep for a while.
484 * \param L a Lua state
485 * \return number of values returned to Lua
487 * - Argument 1 (number): duration of the sleep
489 static int l_host_sleep(lua_State *L)
491 int time = luaL_checknumber(L, 1);
492 MSG_process_sleep(time);
497 * \brief Destroys a host.
498 * \param L a Lua state
499 * \return number of values returned to Lua
501 * - Argument 1 (host): the host to destroy
503 static int l_host_destroy(lua_State *L)
505 m_host_t ht = sglua_checkhost(L, 1);
506 __MSG_host_destroy(ht);
510 static const luaL_reg host_functions[] = {
511 {"get_by_name", l_host_get_by_name},
512 {"name", l_host_get_name},
513 {"number", l_host_number},
515 {"self", l_host_self},
516 {"get_prop_value", l_host_get_property_value},
517 {"sleep", l_host_sleep},
518 {"destroy", l_host_destroy},
519 // Bypass XML Methods
520 {"set_function", console_set_function},
521 {"set_property", console_host_set_property},
526 * \brief Returns a string representation of a host.
527 * \param L a Lua state
528 * \return number of values returned to Lua
530 * - Argument 1 (userdata): a host
531 * - Return value (string): a string describing this host
533 static int l_host_tostring(lua_State * L)
535 lua_pushfstring(L, "Host :%p", lua_touserdata(L, 1));
539 static const luaL_reg host_meta[] = {
540 {"__tostring", l_host_tostring},
544 /* ********************************************************************************* */
545 /* lua_stub_generator functions */
546 /* ********************************************************************************* */
548 xbt_dict_t process_function_set;
549 xbt_dynar_t process_list;
550 xbt_dict_t machine_set;
551 static s_process_t process;
553 void s_process_free(void *process)
555 s_process_t *p = (s_process_t *) process;
557 for (i = 0; i < p->argc; i++)
563 static int gras_add_process_function(lua_State * L)
566 const char *process_host = luaL_checkstring(L, 1);
567 const char *process_function = luaL_checkstring(L, 2);
569 if (xbt_dict_is_empty(machine_set)
570 || xbt_dict_is_empty(process_function_set)
571 || xbt_dynar_is_empty(process_list)) {
572 process_function_set = xbt_dict_new();
573 process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free);
574 machine_set = xbt_dict_new();
577 xbt_dict_set(machine_set, process_host, NULL, NULL);
578 xbt_dict_set(process_function_set, process_function, NULL, NULL);
581 process.argv = xbt_new(char *, 1);
582 process.argv[0] = xbt_strdup(process_function);
583 process.host = strdup(process_host);
586 while (lua_next(L, 3) != 0) {
587 arg = lua_tostring(L, -1);
590 xbt_realloc(process.argv, (process.argc) * sizeof(char *));
591 process.argv[(process.argc) - 1] = xbt_strdup(arg);
593 XBT_DEBUG("index = %f , arg = %s \n", lua_tonumber(L, -2),
594 lua_tostring(L, -1));
598 //add to the process list
599 xbt_dynar_push(process_list, &process);
603 static int gras_generate(lua_State * L)
605 const char *project_name = luaL_checkstring(L, 1);
606 generate_sim(project_name);
607 generate_rl(project_name);
608 generate_makefile_local(project_name);
612 /* ********************************************************************************* */
613 /* simgrid.platf API */
614 /* ********************************************************************************* */
616 static const luaL_reg platf_functions[] = {
617 {"open", console_open},
618 {"close", console_close},
619 {"AS_open", console_AS_open},
620 {"AS_close", console_AS_close},
621 {"host_new", console_add_host},
622 {"link_new", console_add_link},
623 {"router_new", console_add_router},
624 {"route_new", console_add_route},
628 /* ********************************************************************************* */
630 /* ********************************************************************************* */
633 * \brief Deploys your application.
634 * \param L a Lua state
635 * \return number of values returned to Lua
637 * - Argument 1 (string): name of the deployment file to load
639 static int launch_application(lua_State * L)
641 const char *file = luaL_checkstring(L, 1);
642 MSG_function_register_default(run_lua_code);
643 MSG_launch_application(file);
648 * \brief Creates the platform.
649 * \param L a Lua state
650 * \return number of values returned to Lua
652 * - Argument 1 (string): name of the platform file to load
654 static int create_environment(lua_State * L)
656 const char *file = luaL_checkstring(L, 1);
657 XBT_DEBUG("Loading environment file %s", file);
658 MSG_create_environment(file);
663 * \brief Prints a log string with debug level.
664 * \param L a Lua state
665 * \return number of values returned to Lua
667 * - Argument 1 (string): the text to print
669 static int debug(lua_State * L)
671 const char *str = luaL_checkstring(L, 1);
672 XBT_DEBUG("%s", str);
677 * \brief Prints a log string with info level.
678 * \param L a Lua state
679 * \return number of values returned to Lua
681 * - Argument 1 (string): the text to print
683 static int info(lua_State * L)
685 const char *str = luaL_checkstring(L, 1);
691 * \brief Runs your application.
692 * \param L a Lua state
693 * \return number of values returned to Lua
695 static int run(lua_State * L)
702 * \brief Cleans the simulation.
703 * \param L a Lua state
704 * \return number of values returned to Lua
706 static int clean(lua_State * L)
713 * Register platform for MSG
715 static int msg_register_platform(lua_State * L)
717 /* Tell Simgrid we dont wanna use its parser */
718 //surf_parse = console_parse_platform;
719 surf_parse_reset_callbacks();
720 MSG_create_environment(NULL);
725 * Register platform for Simdag
728 static int sd_register_platform(lua_State * L)
730 //surf_parse = console_parse_platform_wsL07;
731 surf_parse_reset_callbacks();
732 SD_create_environment(NULL);
737 * Register platform for gras
739 static int gras_register_platform(lua_State * L)
741 //surf_parse = console_parse_platform;
742 surf_parse_reset_callbacks();
743 gras_create_environment(NULL);
748 * Register applicaiton for MSG
750 static int msg_register_application(lua_State * L)
752 MSG_function_register_default(run_lua_code);
753 //surf_parse = console_parse_application;
754 MSG_launch_application(NULL);
759 * Register application for gras
761 static int gras_register_application(lua_State * L)
763 gras_function_register_default(run_lua_code);
764 //surf_parse = console_parse_application;
765 gras_launch_application(NULL);
769 static const luaL_Reg simgrid_functions[] = {
770 {"create_environment", create_environment},
771 {"launch_application", launch_application},
777 {"platform", create_environment},
778 {"application", launch_application},
779 /* methods to bypass XML parser */
780 {"msg_register_platform", msg_register_platform},
781 {"sd_register_platform", sd_register_platform},
782 {"msg_register_application", msg_register_application},
783 {"gras_register_platform", gras_register_platform},
784 {"gras_register_application", gras_register_application},
785 /* gras sub generator method */
786 {"gras_set_process_function", gras_add_process_function},
787 {"gras_generate", gras_generate},
791 /* ********************************************************************************* */
792 /* module management functions */
793 /* ********************************************************************************* */
795 #define LUA_MAX_ARGS_COUNT 10 /* maximum amount of arguments we can get from lua on command line */
798 * \brief Opens the simgrid Lua module.
800 * This function is called automatically by the Lua interpreter when some
801 * Lua code requires the "simgrid" module.
803 * \param L the Lua state
805 int luaopen_simgrid(lua_State *L)
807 XBT_DEBUG("luaopen_simgrid *****");
809 /* Get the command line arguments from the lua interpreter */
810 char **argv = malloc(sizeof(char *) * LUA_MAX_ARGS_COUNT);
812 argv[0] = (char *) "/usr/bin/lua"; /* Lie on the argv[0] so that the stack dumping facilities find the right binary. FIXME: what if lua is not in that location? */
814 lua_getglobal(L, "arg");
815 /* if arg is a null value, it means we use lua only as a script to init platform
816 * else it should be a table and then take arg in consideration
818 if (lua_istable(L, -1)) {
822 lua_pushinteger(L, argc - 2);
824 if (lua_isnil(L, -1)) {
827 xbt_assert(lua_isstring(L, -1),
828 "argv[%d] got from lua is no string", argc - 1);
829 xbt_assert(argc < LUA_MAX_ARGS_COUNT,
830 "Too many arguments, please increase LUA_MAX_ARGS_COUNT in %s before recompiling SimGrid if you insist on having more than %d args on command line",
831 __FILE__, LUA_MAX_ARGS_COUNT - 1);
832 argv[argc - 1] = (char *) luaL_checkstring(L, -1);
834 XBT_DEBUG("Got command line argument %s from lua", argv[argc - 1]);
839 /* Initialize the MSG core */
840 MSG_global_init(&argc, argv);
841 XBT_DEBUG("Still %d arguments on command line", argc); // FIXME: update the lua's arg table to reflect the changes from SimGrid
844 /* Keep the context mechanism informed of our lua world today */
845 sglua_maestro_state = L;
847 /* initialize access to my tables by children Lua states */
849 lua_setfield(L, LUA_REGISTRYINDEX, "simgrid.maestro_tables");
851 register_c_functions(L);
857 * \brief Returns whether a Lua state is the maestro state.
858 * \param L a Lua state
859 * \return true if this is maestro
861 int sglua_is_maestro(lua_State* L) {
862 return L == sglua_maestro_state;
866 * \brief Returns the maestro state.
867 * \return the maestro Lua state
869 lua_State* sglua_get_maestro(void) {
870 return sglua_maestro_state;
874 * \brief Makes the appropriate Simgrid functions available to the Lua world.
875 * \param L a Lua world
877 void register_c_functions(lua_State *L) {
879 /* register the core C functions to lua */
880 luaL_register(L, "simgrid", simgrid_functions);
882 /* register the task methods to lua */
883 luaL_openlib(L, TASK_MODULE_NAME, task_functions, 0); // create methods table, add it to the globals
884 luaL_newmetatable(L, TASK_MODULE_NAME); // create metatable for Task, add it to the Lua registry
885 luaL_openlib(L, 0, task_meta, 0); // fill metatable
886 lua_pushliteral(L, "__index");
887 lua_pushvalue(L, -3); // dup methods table
888 lua_rawset(L, -3); // metatable.__index = methods
889 lua_pushliteral(L, "__metatable");
890 lua_pushvalue(L, -3); // dup methods table
891 lua_rawset(L, -3); // hide metatable:metatable.__metatable = methods
892 lua_pop(L, 1); // drop metatable
894 /* register the hosts methods to lua */
895 luaL_openlib(L, HOST_MODULE_NAME, host_functions, 0);
896 luaL_newmetatable(L, HOST_MODULE_NAME);
897 luaL_openlib(L, 0, host_meta, 0);
898 lua_pushliteral(L, "__index");
899 lua_pushvalue(L, -3);
901 lua_pushliteral(L, "__metatable");
902 lua_pushvalue(L, -3);
906 /* register the platform methods to lua */
907 luaL_openlib(L, PLATF_MODULE_NAME, platf_functions, 0);
908 luaL_newmetatable(L, PLATF_MODULE_NAME);
913 * \brief Runs a Lua function as a new simulated process.
914 * \param argc number of arguments of the function
915 * \param argv name of the Lua function and array of its arguments
916 * \return result of the function
918 static int run_lua_code(int argc, char **argv)
920 XBT_DEBUG("Run lua code %s", argv[0]);
922 lua_State *L = sglua_clone_maestro();
925 /* start the function */
926 lua_getglobal(L, argv[0]);
927 xbt_assert(lua_isfunction(L, -1),
928 "The lua function %s does not seem to exist", argv[0]);
930 /* push arguments onto the stack */
932 for (i = 1; i < argc; i++)
933 lua_pushstring(L, argv[i]);
935 /* call the function */
936 _XBT_GNUC_UNUSED int err;
937 err = lua_pcall(L, argc - 1, 1, 0);
938 xbt_assert(err == 0, "error running function `%s': %s", argv[0],
939 lua_tostring(L, -1));
941 /* retrieve result */
942 if (lua_isnumber(L, -1)) {
943 res = lua_tonumber(L, -1);
944 lua_pop(L, 1); /* pop returned value */
947 XBT_DEBUG("Execution of Lua code %s is over", (argv ? argv[0] : "(null)"));