1 /* SimGrid Lua bindings */
3 /* Copyright (c) 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua,bindings,"Lua Bindings");
17 #define TASK_MODULE_NAME "simgrid.Task"
18 #define HOST_MODULE_NAME "simgrid.Host"
19 // Surf ( bypass XML )
20 #define LINK_MODULE_NAME "simgrid.Link"
21 #define ROUTE_MODULE_NAME "simgrid.Route"
23 /* ********************************************************************************* */
24 /* helper functions */
25 /* ********************************************************************************* */
27 static void stackDump (const char *msg, lua_State *L) {
31 int top = lua_gettop(L);
34 p+=sprintf(p,"STACK(top=%d): ",top);
36 for (i = 1; i <= top; i++) { /* repeat for each level */
37 int t = lua_type(L, i);
40 case LUA_TSTRING: /* strings */
41 p+=sprintf(p,"`%s'", lua_tostring(L, i));
44 case LUA_TBOOLEAN: /* booleans */
45 p+=sprintf(p,lua_toboolean(L, i) ? "true" : "false");
48 case LUA_TNUMBER: /* numbers */
49 p+=sprintf(p,"%g", lua_tonumber(L, i));
53 p+=sprintf(p, "Table");
56 default: /* other values */
58 /* if ((ptr = luaL_checkudata(L,i,TASK_MODULE_NAME))) {
61 p+=printf(p,"%s", lua_typename(L, t));
66 p+=sprintf(p," "); /* put a separator */
68 INFO2("%s%s",msg,buff);
71 /** @brief ensures that a userdata on the stack is a task and returns the pointer inside the userdata */
72 static m_task_t checkTask (lua_State *L,int index) {
74 luaL_checktype(L,index,LUA_TTABLE);
75 lua_getfield(L,index,"__simgrid_task");
76 pi = (m_task_t*)luaL_checkudata(L,-1,TASK_MODULE_NAME);
78 luaL_typerror(L,index,TASK_MODULE_NAME);
81 luaL_error(L,"null Task");
86 /** @brief leaves a new userdata on top of the stack, sets its metatable, and sets the Task pointer inside the userdata */
88 /*static m_task_t *pushTask (lua_State *L,m_task_t tk) {
90 pi = (m_task_t*)lua_newuserdata(L,sizeof(m_task_t));
92 DEBUG1("push lua task with Name : %s \n",MSG_task_get_name(*pi));
93 luaL_getmetatable(L,TASK_MODULE_NAME);
94 lua_setmetatable(L,-2);
98 /* ********************************************************************************* */
99 /* wrapper functions */
100 /* ********************************************************************************* */
106 static int Task_new(lua_State* L) {
107 const char *name=luaL_checkstring(L,1);
108 int comp_size = luaL_checkint(L,2);
109 int msg_size = luaL_checkint(L,3);
110 INFO0("Creating task");
111 m_task_t msg_task = MSG_task_create(name,comp_size,msg_size,NULL);
112 lua_newtable (L); /* create a table, put the userdata on top of it */
113 m_task_t *lua_task = (m_task_t*)lua_newuserdata(L,sizeof(m_task_t));
114 *lua_task = msg_task;
115 luaL_getmetatable(L,TASK_MODULE_NAME);
116 lua_setmetatable(L,-2);
117 lua_setfield (L, -2, "__simgrid_task"); /* put the userdata as field of the table */
118 /* remove the args from the stack */
125 static int Task_get_name(lua_State *L) {
126 m_task_t tk = checkTask(L,-1);
127 lua_pushstring(L,MSG_task_get_name(tk));
131 static int Task_computation_duration(lua_State *L){
132 m_task_t tk = checkTask(L,-1);
133 lua_pushnumber(L,MSG_task_get_compute_duration (tk));
137 static int Task_execute(lua_State *L){
138 m_task_t tk = checkTask(L,-1);
139 int res = MSG_task_execute(tk);
140 lua_pushnumber(L,res);
144 static int Task_destroy(lua_State *L) {
145 m_task_t tk = checkTask(L,-1);
146 int res = MSG_task_destroy(tk);
147 lua_pushnumber(L,res);
151 static int Task_send(lua_State *L) {
152 //stackDump("send ",L);
153 m_task_t tk = checkTask(L,-2);
154 const char *mailbox = luaL_checkstring(L,-1);
155 lua_pop(L,1); // remove the string so that the task is on top of it
156 MSG_task_set_data(tk,L); // Copy my stack into the task, so that the receiver can copy the lua task directly
157 MSG_error_t res = MSG_task_send(tk,mailbox);
158 while (MSG_task_get_data(tk)!=NULL) // Don't mess up with my stack: the receiver didn't copy the data yet
159 MSG_process_sleep(0); // yield
161 if (res != MSG_OK) switch(res) {
163 ERROR0("MSG_task_send failed : Timeout");
165 case MSG_TRANSFER_FAILURE :
166 ERROR0("MSG_task_send failed : Transfer Failure");
168 case MSG_HOST_FAILURE :
169 ERROR0("MSG_task_send failed : Host Failure ");
172 ERROR0("MSG_task_send failed : Unexpected error , please report this bug");
178 static int Task_recv(lua_State *L) {
180 const char *mailbox = luaL_checkstring(L,-1);
181 MSG_error_t res = MSG_task_receive(&tk,mailbox);
183 lua_State *sender_stack = MSG_task_get_data(tk);
184 lua_xmove(sender_stack,L,1); // copy the data directly from sender's stack
185 MSG_task_set_data(tk,NULL);
187 if(res != MSG_OK) switch(res){
189 ERROR0("MSG_task_receive failed : Timeout");
191 case MSG_TRANSFER_FAILURE :
192 ERROR0("MSG_task_receive failed : Transfer Failure");
194 case MSG_HOST_FAILURE :
195 ERROR0("MSG_task_receive failed : Host Failure ");
198 ERROR0("MSG_task_receive failed : Unexpected error , please report this bug");
205 static const luaL_reg Task_methods[] = {
207 {"name", Task_get_name},
208 {"computation_duration", Task_computation_duration},
209 {"execute", Task_execute},
210 {"destroy", Task_destroy},
215 static int Task_gc(lua_State *L) {
216 m_task_t tk=checkTask(L,-1);
217 if (tk) MSG_task_destroy(tk);
221 static int Task_tostring(lua_State *L) {
222 lua_pushfstring(L, "Task :%p",lua_touserdata(L,1));
226 static const luaL_reg Task_meta[] = {
228 {"__tostring", Task_tostring},
235 static m_host_t checkHost (lua_State *L,int index) {
237 luaL_checktype(L,index,LUA_TTABLE);
238 lua_getfield(L,index,"__simgrid_host");
239 pi = (m_host_t*)luaL_checkudata(L,-1,HOST_MODULE_NAME);
241 luaL_typerror(L,index,HOST_MODULE_NAME);
244 luaL_error(L,"null Host");
249 static int Host_get_by_name(lua_State *L)
251 const char *name=luaL_checkstring(L,1);
252 DEBUG0("Getting Host from name...");
253 m_host_t msg_host = MSG_get_host_by_name(name);
256 luaL_error(L,"null Host : MSG_get_host_by_name failled");
258 lua_newtable (L); /* create a table, put the userdata on top of it */
259 m_host_t *lua_host = (m_host_t*)lua_newuserdata(L,sizeof(m_host_t));
260 *lua_host = msg_host;
261 luaL_getmetatable(L,HOST_MODULE_NAME);
262 lua_setmetatable(L,-2);
263 lua_setfield (L, -2, "__simgrid_host"); /* put the userdata as field of the table */
264 /* remove the args from the stack */
270 static int Host_get_name(lua_State *L) {
271 m_host_t ht = checkHost(L,-1);
272 lua_pushstring(L,MSG_host_get_name(ht));
276 static int Host_number(lua_State *L) {
277 lua_pushnumber(L,MSG_get_host_number());
281 static int Host_at(lua_State *L)
283 int index = luaL_checkinteger(L,1);
284 m_host_t host = MSG_get_host_table()[index-1]; // lua indexing start by 1 (lua[1] <=> C[0])
285 lua_newtable (L); /* create a table, put the userdata on top of it */
286 m_host_t *lua_host = (m_host_t*)lua_newuserdata(L,sizeof(m_host_t));
288 luaL_getmetatable(L,HOST_MODULE_NAME);
289 lua_setmetatable(L,-2);
290 lua_setfield (L, -2, "__simgrid_host"); /* put the userdata as field of the table */
295 /*****************************************************************************************
296 * BYPASS XML SURF Methods *
297 ***************************
298 ***************************
299 ******************************************************************************************/
300 #include "surf/surfxml_parse.h" /* to override surf_parse and bypass the parser */
301 typedef struct t_host_attr
306 //deployment attribute
307 const char* function;
309 const char ** args_list;
310 }host_attr,*p_host_attr;
312 typedef struct t_link_attr
317 }link_attr,*p_link_attr;
319 typedef struct t_route_attr
324 const char **links_id;
326 }route_attr,*p_route_attr;
329 static int host_index = 0;
330 static int link_index = 0;
331 static int route_index = 0;
333 static int max_host_number = 0;
334 static int max_link_number = 0;
335 static int max_route_number = 0;
338 //using xbt_dynar_t :
339 static xbt_dynar_t host_list_d ;
340 static xbt_dynar_t link_list_d ;
341 static xbt_dynar_t route_list_d ;
344 static int Host_set_number(lua_State *L)
346 max_host_number = luaL_checkint(L,1);
347 // host_list = malloc(sizeof(host_attr)*max_host_number);
348 //host_list_d = xbt_dynar_new(sizeof(p_host_attr), &xbt_free_ref);
353 static int Link_set_number(lua_State *L)
355 max_link_number = luaL_checkint(L,1);
356 //link_list = malloc(sizeof(link_attr)*max_link_number);
357 //link_list_d = xbt_dynar_new(sizeof(p_link_attr),&xbt_free_ref);
361 static int Route_set_number(lua_State *L)
363 max_route_number = luaL_checkint(L,1);
364 //route_list = malloc(sizeof(route_attr)*max_link_number);
365 //route_list_d = xbt_dynar_new(sizeof(p_route_attr),&xbt_free_ref);
369 static int Host_new(lua_State *L) //(id,power)
371 // if it's the first time ,instanciate the dynar
372 if(xbt_dynar_is_empty(host_list_d))
373 host_list_d = xbt_dynar_new(sizeof(p_host_attr), &xbt_free_ref);
376 p_host_attr host = malloc(sizeof(host_attr));
377 host->id = luaL_checkstring(L,1);
378 host->power = luaL_checknumber(L,2);
379 host->function = NULL;
380 xbt_dynar_push(host_list_d, &host);
385 static int Link_new(lua_State *L) // (id,bandwidth,latency)
387 if(xbt_dynar_is_empty(link_list_d))
388 link_list_d = xbt_dynar_new(sizeof(p_link_attr), &xbt_free_ref);
390 p_link_attr link = malloc(sizeof(link_attr));
391 link->id = luaL_checkstring(L,1);
392 link->bandwidth = luaL_checknumber(L,2);
393 link->latency = luaL_checknumber(L,3);
394 xbt_dynar_push(link_list_d,&link);
399 static int Route_new(lua_State *L) // (src_id,dest_id,links_number,link_table)
401 if(xbt_dynar_is_empty(route_list_d))
402 route_list_d = xbt_dynar_new(sizeof(p_route_attr), &xbt_free_ref);
405 p_route_attr route = malloc(sizeof(route_attr));
406 route->src_id = luaL_checkstring(L,1);
407 route->dest_id = luaL_checkstring(L,2);
408 route->links_nb = luaL_checkint(L,3);
409 route->links_id = malloc(sizeof(char*)*route->links_nb);
411 while (lua_next(L,4) != 0) {
412 if(i >= route->links_nb)
413 ERROR1("Number of links should be less than %d",route->links_nb+1);
414 route->links_id[i] = lua_tostring(L, -1);
415 DEBUG2("index = %f , Link_id = %s \n",lua_tonumber(L, -2),lua_tostring(L, -1));
421 //add route to platform's route list
422 xbt_dynar_push(route_list_d,&route);
427 static int Host_set_function(lua_State *L) //(host,function,nb_args,list_args)
429 // look for the index of host in host_list
430 const char *host_id = luaL_checkstring(L,1);
434 xbt_dynar_foreach(host_list_d,i,p_host)
436 if(p_host->id == host_id)
438 p_host->function = luaL_checkstring(L,2);
439 p_host->args_nb = luaL_checkint(L,3);
440 p_host->args_list = malloc(sizeof(char*)*p_host->args_nb);
441 // fill the args list
444 while (lua_next(L,4) != 0) {
445 if(j >= p_host->args_nb)
446 ERROR1("Number of args should be less than %d",p_host->args_nb+1);
447 p_host->args_list[j] = lua_tostring(L, -1);
448 DEBUG2("index = %f , Arg_id = %s \n",lua_tonumber(L, -2),lua_tostring(L, -1));
456 ERROR1("Host : %s Not Fount !!",host_id);
463 * surf parse bypass platform
465 static int surf_parse_bypass_platform()
472 p_route_attr p_route;
474 xbt_dynar_t dynaroun = xbt_dynar_new(sizeof(int), NULL);
476 static int AX_ptr = 0;
477 static int surfxml_bufferstack_size = 2048;
479 /* FIXME allocating memory for the buffer, I think 2kB should be enough */
480 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
482 SURFXML_BUFFER_SET(platform_version, "2");
483 SURFXML_START_TAG(platform);
487 //for(i=0;i<host_index;i++)
488 xbt_dynar_foreach(host_list_d,i,p_host)
490 //SURFXML_BUFFER_SET(host_id,host_list[i]->id);
491 SURFXML_BUFFER_SET(host_id,p_host->id);
492 //sprintf(buffer, "%f", host_list[i]->power);
493 sprintf(buffer,"%f",p_host->power);
494 SURFXML_BUFFER_SET(host_power,buffer);
495 SURFXML_BUFFER_SET(host_availability, "1.0");
496 SURFXML_BUFFER_SET(host_availability_file, "");
497 A_surfxml_host_state = A_surfxml_host_state_ON;
498 SURFXML_BUFFER_SET(host_state_file, "");
499 SURFXML_BUFFER_SET(host_interference_send, "1.0");
500 SURFXML_BUFFER_SET(host_interference_recv, "1.0");
501 SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
502 SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
503 SURFXML_START_TAG(host);
504 SURFXML_END_TAG(host);
508 //for (i = 0;i<link_index;i++)
509 xbt_dynar_foreach(link_list_d,i,p_link)
511 //SURFXML_BUFFER_SET(link_id,link_list[i]->id);
512 SURFXML_BUFFER_SET(link_id,p_link->id);
513 //sprintf(buffer,"%f",link_list[i]->bandwidth);
514 sprintf(buffer,"%f",p_link->bandwidth);
515 SURFXML_BUFFER_SET(link_bandwidth,buffer);
516 SURFXML_BUFFER_SET(link_bandwidth_file, "");
517 //sprintf(buffer,"%f",link_list[i]->latency);
518 sprintf(buffer,"%f",p_link->latency);
519 SURFXML_BUFFER_SET(link_latency,buffer);
520 SURFXML_BUFFER_SET(link_latency_file, "");
521 A_surfxml_link_state = A_surfxml_link_state_ON;
522 SURFXML_BUFFER_SET(link_state_file, "");
523 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
524 SURFXML_START_TAG(link);
525 SURFXML_END_TAG(link);
530 //for (i = 0;i<route_index;i++)
531 xbt_dynar_foreach(route_list_d,i,p_route)
533 //SURFXML_BUFFER_SET(route_src,route_list[i]->src_id);
534 SURFXML_BUFFER_SET(route_src,p_route->src_id);
535 //SURFXML_BUFFER_SET(route_dst,route_list[i]->dest_id);
536 SURFXML_BUFFER_SET(route_dst,p_route->dest_id);
537 SURFXML_BUFFER_SET(route_impact_on_src, "0.0");
538 SURFXML_BUFFER_SET(route_impact_on_dst, "0.0");
539 SURFXML_BUFFER_SET(route_impact_on_src_with_other_recv, "0.0");
540 SURFXML_BUFFER_SET(route_impact_on_dst_with_other_send, "0.0");
541 SURFXML_START_TAG(route);
544 //for(j=0; j < route_list[i]->links_nb;j++)
545 for(j=0;j< p_route->links_nb;j++)
547 //SURFXML_BUFFER_SET(link_c_ctn_id,route_list[i]->links_id[j]);
548 SURFXML_BUFFER_SET(link_c_ctn_id,p_route->links_id[j]);
549 SURFXML_START_TAG(link_c_ctn);
550 SURFXML_END_TAG(link_c_ctn);
553 SURFXML_END_TAG(route);
557 SURFXML_END_TAG(platform);
558 free(surfxml_bufferstack);
559 return 0; // must return 0 ?!!
564 * surf parse bypass application
566 static int surf_parse_bypass_application()
574 static int surfxml_bufferstack_size = 2048;
575 /* FIXME ( should be manual )allocating memory to the buffer, I think 2MB should be enough */
576 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
579 SURFXML_BUFFER_SET(platform_version, "2");
581 SURFXML_START_TAG(platform);
583 //for(i=0 ; i< host_index ;i++)
584 xbt_dynar_foreach(host_list_d,i,p_host)
588 SURFXML_BUFFER_SET(process_host, p_host->id);
589 SURFXML_BUFFER_SET(process_function, p_host->function);
590 SURFXML_BUFFER_SET(process_start_time, "-1.0");
591 SURFXML_BUFFER_SET(process_kill_time, "-1.0");
592 SURFXML_START_TAG(process);
596 for(j=0 ;j<p_host->args_nb;j++)
598 SURFXML_BUFFER_SET(argument_value,p_host->args_list[j]);
599 SURFXML_START_TAG(argument);
600 SURFXML_END_TAG(argument);
602 SURFXML_END_TAG(process);
607 SURFXML_END_TAG(platform);
608 free(surfxml_bufferstack);
612 // Free Allocated Memory
613 static void clean_attr()
617 //***********Register Methods *******************************************//
621 static const luaL_reg Host_methods[] = {
622 {"getByName", Host_get_by_name},
623 {"name", Host_get_name},
624 {"number", Host_number},
626 // Bypass XML Methods
628 {"setNumber", Host_set_number},
629 {"setFunction", Host_set_function},
633 static int Host_gc(lua_State *L)
635 m_host_t ht = checkHost(L,-1);
640 static int Host_tostring(lua_State *L)
642 lua_pushfstring(L,"Host :%p",lua_touserdata(L,1));
646 static const luaL_reg Host_meta[] = {
648 {"__tostring", Host_tostring},
655 static const luaL_reg Link_methods[] = {
657 {"setNumber", Link_set_number },
663 static const luaL_reg Route_methods[] ={
665 {"setNumber",Route_set_number}
669 * Environment related
672 extern lua_State *simgrid_lua_state;
674 static int run_lua_code(int argc,char **argv) {
675 DEBUG1("Run lua code %s",argv[0]);
676 lua_State *L = lua_newthread(simgrid_lua_state);
677 int ref = luaL_ref(simgrid_lua_state, LUA_REGISTRYINDEX); // protect the thread from being garbage collected
680 /* Start the co-routine */
681 lua_getglobal(L,argv[0]);
682 xbt_assert1(lua_isfunction(L,-1),
683 "The lua function %s does not seem to exist",argv[0]);
685 // push arguments onto the stack
688 lua_pushstring(L,argv[i]);
690 // Call the function (in resume)
691 xbt_assert2(lua_pcall(L, argc-1, 1, 0) == 0,
692 "error running function `%s': %s",argv[0], lua_tostring(L, -1));
694 /* retrieve result */
695 if (lua_isnumber(L, -1)) {
696 res = lua_tonumber(L, -1);
697 lua_pop(L, 1); /* pop returned value */
701 luaL_unref(simgrid_lua_state,LUA_REGISTRYINDEX,ref );
702 DEBUG1("Execution of lua code %s is over", (argv ? argv[0] : "(null)"));
705 static int launch_application(lua_State *L) {
706 const char * file = luaL_checkstring(L,1);
707 MSG_function_register_default(run_lua_code);
708 MSG_launch_application(file);
711 #include "simix/simix.h" //FIXME: KILLME when debugging on simix internals become useless
712 static int create_environment(lua_State *L) {
713 const char *file = luaL_checkstring(L,1);
714 DEBUG1("Loading environment file %s",file);
715 MSG_create_environment(file);
716 smx_host_t *hosts = SIMIX_host_get_table();
718 for (i=0;i<SIMIX_host_get_number();i++) {
719 DEBUG1("We have an host %s", SIMIX_host_get_name(hosts[i]));
725 static int debug(lua_State *L) {
726 const char *str = luaL_checkstring(L,1);
730 static int info(lua_State *L) {
731 const char *str = luaL_checkstring(L,1);
735 static int run(lua_State *L) {
739 static int clean(lua_State *L) {
740 clean_attr(); // in case of using "bypass xml" methods
748 static int register_platform(lua_State *L)
750 /* Tell Simgrid we dont wanna use its parser*/
751 surf_parse = surf_parse_bypass_platform;
752 MSG_create_environment(NULL);
756 static int register_application(lua_State *L)
758 MSG_function_register_default(run_lua_code);
759 surf_parse = surf_parse_bypass_application;
760 MSG_launch_application(NULL);
764 static const luaL_Reg simgrid_funcs[] = {
765 { "create_environment", create_environment},
766 { "launch_application", launch_application},
772 { "platform", create_environment},
773 { "application", launch_application},
774 /* methods to bypass XML parser*/
775 { "register_platform",register_platform},
776 { "register_application",register_application},
780 /* ********************************************************************************* */
781 /* module management functions */
782 /* ********************************************************************************* */
784 extern const char*xbt_ctx_factory_to_use; /*Hack: let msg load directly the right factory */
786 #define LUA_MAX_ARGS_COUNT 10 /* maximum amount of arguments we can get from lua on command line */
788 int luaopen_simgrid(lua_State* L); // Fuck gcc: we don't need that prototype
789 int luaopen_simgrid(lua_State* L) {
790 //xbt_ctx_factory_to_use = "lua";
792 char **argv=malloc(sizeof(char*)*LUA_MAX_ARGS_COUNT);
794 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? */
795 /* Get the command line arguments from the lua interpreter */
796 lua_getglobal(L,"arg");
797 xbt_assert1(lua_istable(L,-1),"arg parameter is not a table but a %s",lua_typename(L,-1));
801 lua_pushinteger(L,argc-2);
803 if (lua_isnil(L,-1)) {
806 xbt_assert1(lua_isstring(L,-1),"argv[%d] got from lua is no string",argc-1);
807 xbt_assert2(argc<LUA_MAX_ARGS_COUNT,
808 "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",
809 __FILE__,LUA_MAX_ARGS_COUNT-1);
810 argv[argc-1] = (char*)luaL_checkstring(L,-1);
812 DEBUG1("Got command line argument %s from lua",argv[argc-1]);
817 /* Initialize the MSG core */
818 MSG_global_init(&argc,argv);
819 DEBUG1("Still %d arguments on command line",argc); // FIXME: update the lua's arg table to reflect the changes from SimGrid
821 /* register the core C functions to lua */
822 luaL_register(L, "simgrid", simgrid_funcs);
823 /* register the task methods to lua */
824 luaL_openlib(L,TASK_MODULE_NAME,Task_methods,0); //create methods table,add it to the globals
825 luaL_newmetatable(L,TASK_MODULE_NAME); //create metatable for Task,add it to the Lua registry
826 luaL_openlib(L,0,Task_meta,0);// fill metatable
827 lua_pushliteral(L,"__index");
828 lua_pushvalue(L,-3); //dup methods table
829 lua_rawset(L,-3); //matatable.__index = methods
830 lua_pushliteral(L,"__metatable");
831 lua_pushvalue(L,-3); //dup methods table
832 lua_rawset(L,-3); //hide metatable:metatable.__metatable = methods
833 lua_pop(L,1); //drop metatable
835 /* register the hosts methods to lua*/
836 luaL_openlib(L,HOST_MODULE_NAME,Host_methods,0);
837 luaL_newmetatable(L,HOST_MODULE_NAME);
838 luaL_openlib(L,0,Host_meta,0);
839 lua_pushliteral(L,"__index");
842 lua_pushliteral(L,"__metatable");
847 /* register the links methods to lua*/
848 luaL_openlib(L,LINK_MODULE_NAME,Link_methods,0);
849 luaL_newmetatable(L,LINK_MODULE_NAME);
852 /*register the routes methods to lua*/
853 luaL_openlib(L,ROUTE_MODULE_NAME,Route_methods,0);
854 luaL_newmetatable(L,LINK_MODULE_NAME);
857 /* Keep the context mechanism informed of our lua world today */
858 simgrid_lua_state = L;