/** * \brief Runs a Lua function as a new simulated process. * \param argc number of arguments of the function * \param argv name of the Lua function and array of its arguments * \return result of the function */ static int run_lua_code(int argc, char **argv) { XBT_DEBUG("Run lua code %s", argv[0]); /* create a new state, getting globals from maestro */ lua_State *L = sglua_clone_maestro(); MSG_process_set_data(MSG_process_self(), L); /* start the function */ lua_getglobal(L, argv[0]); xbt_assert(lua_isfunction(L, -1), "There is no Lua function with name `%s'", argv[0]); /* push arguments onto the stack */ int i; for (i = 1; i < argc; i++) lua_pushstring(L, argv[i]); /* call the function */ _XBT_GNUC_UNUSED int err; err = lua_pcall(L, argc - 1, 1, 0); xbt_assert(err == 0, "Error running function `%s': %s", argv[0], lua_tostring(L, -1)); /* retrieve result */ int res = 1; if (lua_isnumber(L, -1)) { res = lua_tonumber(L, -1); lua_pop(L, 1); /* pop returned value */ } XBT_DEBUG("Execution of Lua code %s is over", (argv ? argv[0] : "(null)")); return res; }
static void action_init(const char *const *action) { XBT_DEBUG("Initialize the counters"); process_globals_t globals = (process_globals_t) calloc(1, sizeof(s_process_globals_t)); globals->isends = xbt_dynar_new(sizeof(msg_comm_t), NULL); globals->irecvs = xbt_dynar_new(sizeof(msg_comm_t), NULL); globals->tasks = xbt_dynar_new(sizeof(msg_task_t), NULL); MSG_process_set_data(MSG_process_self(), globals); }