- gras_function_register_default(run_lua_code);
- surf_parse = console_parse_application;
- gras_launch_application(NULL);
- return 0;
-}
-
-static const luaL_Reg simgrid_funcs[] = {
- {"create_environment", create_environment},
- {"launch_application", launch_application},
- {"debug", debug},
- {"info", info},
- {"run", run},
- {"clean", clean},
- /* short names */
- {"platform", create_environment},
- {"application", launch_application},
- /* methods to bypass XML parser */
- {"msg_register_platform", msg_register_platform},
- {"sd_register_platform", sd_register_platform},
- {"msg_register_application", msg_register_application},
- {"gras_register_platform", gras_register_platform},
- {"gras_register_application", gras_register_application},
- /* gras sub generator method */
- {"gras_set_process_function", gras_add_process_function},
- {"gras_generate", gras_generate},
- {NULL, NULL}
-};
-
-/* ********************************************************************************* */
-/* module management functions */
-/* ********************************************************************************* */
-
-
-#define LUA_MAX_ARGS_COUNT 10 /* maximum amount of arguments we can get from lua on command line */
-#define TEST
-int luaopen_simgrid(lua_State * L); // Fuck gcc: we don't need that prototype
-int luaopen_simgrid(lua_State * L)
-{
-
- char **argv = 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? */
- /* Get the command line arguments from the lua interpreter */
- 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_assert1(lua_isstring(L, -1),
- "argv[%d] got from lua is no string", argc - 1);
- xbt_assert2(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 */
- MSG_global_init(&argc, argv);
- XBT_DEBUG("Still %d arguments on command line", argc); // FIXME: update the lua's arg table to reflect the changes from SimGrid
- }
- /* register the core C functions to lua */
- luaL_register(L, "simgrid", simgrid_funcs);
- /* register the task methods to lua */
- luaL_openlib(L, TASK_MODULE_NAME, Task_methods, 0); //create methods table,add it to the globals
- luaL_newmetatable(L, TASK_MODULE_NAME); //create metatable for Task,add it to the Lua registry
- luaL_openlib(L, 0, Task_meta, 0); // fill metatable
- lua_pushliteral(L, "__index");
- lua_pushvalue(L, -3); //dup methods table
- lua_rawset(L, -3); //matatable.__index = methods
- lua_pushliteral(L, "__metatable");
- lua_pushvalue(L, -3); //dup methods table
- lua_rawset(L, -3); //hide metatable:metatable.__metatable = methods
- lua_pop(L, 1); //drop metatable
-
- /* register the hosts methods to lua */
- luaL_openlib(L, HOST_MODULE_NAME, Host_methods, 0);
- luaL_newmetatable(L, HOST_MODULE_NAME);
- luaL_openlib(L, 0, Host_meta, 0);
- lua_pushliteral(L, "__index");
- lua_pushvalue(L, -3);
- lua_rawset(L, -3);
- lua_pushliteral(L, "__metatable");
- lua_pushvalue(L, -3);
- lua_rawset(L, -3);
- lua_pop(L, 1);
-
- /* register the links methods to lua */
- luaL_openlib(L, AS_MODULE_NAME, AS_methods, 0);
- luaL_newmetatable(L, AS_MODULE_NAME);
- lua_pop(L, 1);
-
- /* register the links methods to lua */
- luaL_openlib(L, LINK_MODULE_NAME, Link_methods, 0);
- luaL_newmetatable(L, LINK_MODULE_NAME);
- lua_pop(L, 1);
-
- /*register the routes methods to lua */
- luaL_openlib(L, ROUTE_MODULE_NAME, Route_methods, 0);
- luaL_newmetatable(L, ROUTE_MODULE_NAME);
- lua_pop(L, 1);
-
- /*register the Tracing functions to lua */
- luaL_openlib(L, TRACE_MODULE_NAME, Trace_methods, 0);
- luaL_newmetatable(L, TRACE_MODULE_NAME);
- lua_pop(L, 1);
-
- /* Keep the context mechanism informed of our lua world today */
- simgrid_lua_state = L;
- return 1;