-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
-
- /* 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,LINK_MODULE_NAME);
- lua_pop(L,1);
-
- /* Keep the context mechanism informed of our lua world today */
- simgrid_lua_state = L;
- return 1;