-
-/**
- * \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;
-}
-
-/**
- * \brief Returns a string corresponding to an MSG error code.
- * \param err an MSG error code
- * \return a string describing this error
- */
-const char* sglua_get_msg_error(msg_error_t err) {
-
- static const char* msg_errors[] = {
- NULL,
- "timeout",
- "transfer failure",
- "host failure",
- "task canceled"
- };
-
- return msg_errors[err];
-}