-static int msg_register_application(lua_State *L)
-{
- MSG_function_register_default(run_lua_code);
- surf_parse = surf_parse_bypass_application;
- MSG_launch_application(NULL);
- return 0;
-}
-
-/*
- * Register application for gras
- */
-static int gras_register_application(lua_State *L)
-{
- gras_function_register_default(run_lua_code);
- surf_parse = surf_parse_bypass_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 */
-/* ********************************************************************************* */
-
-extern const char*xbt_ctx_factory_to_use; /*Hack: let msg load directly the right factory */
-
-#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) {
-
- //xbt_ctx_factory_to_use = "lua";
- 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);
- DEBUG1("Got command line argument %s from lua",argv[argc-1]);
- }
- }
- argv[argc--]=NULL;
-
- /* Initialize the MSG core */
- MSG_global_init(&argc,argv);
- DEBUG1("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