return 1;
}
-/**
- * \brief Makes the current process sleep for a while.
- * \param L a Lua state
- * \return number of values returned to Lua
- *
- * - Argument 1 (number): duration of the sleep
- */
-static int l_host_sleep(lua_State *L)
-{
- int time = luaL_checkinteger(L, 1);
- MSG_process_sleep(time);
- return 0;
-}
-
/**
* \brief Destroys a host.
* \param L a Lua state
{"at", l_host_at},
{"self", l_host_self},
{"get_prop_value", l_host_get_property_value},
- {"sleep", l_host_sleep},
{"destroy", l_host_destroy},
// Bypass XML Methods
- {"set_function", console_set_function},
{"set_property", console_host_set_property},
{NULL, NULL}
};
return 0;
}
-int console_set_function(lua_State *L) {
-
- const char *host_id ;
- const char *function_id;
- xbt_dynar_t args;
-
- if (! lua_istable(L, 1)) {
- XBT_ERROR("Bad Arguments to AS.new, Should be a table with named arguments");
- return -1;
- }
-
- // get Host id
- lua_pushstring(L, "host");
- lua_gettable(L, -2);
- host_id = lua_tostring(L, -1);
- lua_pop(L, 1);
-
- // get Function Name
- lua_pushstring(L, "fct");
- lua_gettable(L, -2);
- function_id = lua_tostring(L, -1);
- lua_pop(L, 1);
-
- //get args
- lua_pushstring(L,"args");
- lua_gettable(L, -2);
- args = xbt_str_split_str( lua_tostring(L,-1) , ",");
- lua_pop(L, 1);
-
- msg_host_t host = MSG_host_by_name(host_id);
- if (!host) {
- XBT_ERROR("no host '%s' found",host_id);
- return -1;
- }
-
- // FIXME: use sg_platf_new_process directly (warning: find a way to check hostname)
- MSG_set_function(host_id, function_id, args);
-
- return 0;
-}
-
int console_host_set_property(lua_State *L) {
const char* name ="";
const char* prop_id = "";
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua, bindings, "Lua Bindings");
-static lua_State* sglua_maestro_state;
-
int luaopen_simgrid(lua_State *L);
static void sglua_register_c_functions(lua_State *L);
{
XBT_DEBUG("luaopen_simgrid *****");
- /* Get the command line arguments from the lua interpreter */
- char **argv = xbt_malloc(sizeof(char *) * LUA_MAX_ARGS_COUNT);
- int argc = 1;
- 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? */
-
- lua_getglobal(L, "arg");
- /* if arg is a null value, it means we use lua only as a script to init platform
- * else it should be a table and then take arg in consideration
- */
- if (lua_istable(L, -1)) {
- int done = 0;
- while (!done) {
- argc++;
- lua_pushinteger(L, argc - 2);
- lua_gettable(L, -2);
- if (lua_isnil(L, -1)) {
- done = 1;
- } else {
- xbt_assert(lua_isstring(L, -1),
- "argv[%d] got from lua is no string", argc - 1);
- xbt_assert(argc < LUA_MAX_ARGS_COUNT,
- "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",
- __FILE__, LUA_MAX_ARGS_COUNT - 1);
- argv[argc - 1] = (char *) luaL_checkstring(L, -1);
- lua_pop(L, 1);
- XBT_DEBUG("Got command line argument %s from lua", argv[argc - 1]);
- }
- }
- argv[argc--] = NULL;
-
- /* Initialize the MSG core */
- XBT_DEBUG("Still %d arguments on command line", argc); // FIXME: update the lua's arg table to reflect the changes from SimGrid
- }
- MSG_init(&argc, argv);
- MSG_process_set_data_cleanup((void_f_pvoid_t) lua_close);
-
- /* Keep the context mechanism informed of our lua world today */
- sglua_maestro_state = L;
-
- /* initialize access to my tables by children Lua states */
- lua_newtable(L);
- lua_setfield(L, LUA_REGISTRYINDEX, "simgrid.maestro_tables");
-
sglua_register_c_functions(L);
return 1;