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"
24 /* ********************************************************************************* */
25 /* helper functions */
26 /* ********************************************************************************* */
28 static void stackDump (const char *msg, lua_State *L) {
32 int top = lua_gettop(L);
35 p+=sprintf(p,"STACK(top=%d): ",top);
37 for (i = 1; i <= top; i++) { /* repeat for each level */
38 int t = lua_type(L, i);
41 case LUA_TSTRING: /* strings */
42 p+=sprintf(p,"`%s'", lua_tostring(L, i));
45 case LUA_TBOOLEAN: /* booleans */
46 p+=sprintf(p,lua_toboolean(L, i) ? "true" : "false");
49 case LUA_TNUMBER: /* numbers */
50 p+=sprintf(p,"%g", lua_tonumber(L, i));
54 p+=sprintf(p, "Table");
57 default: /* other values */
59 /* if ((ptr = luaL_checkudata(L,i,TASK_MODULE_NAME))) {
62 p+=printf(p,"%s", lua_typename(L, t));
67 p+=sprintf(p," "); /* put a separator */
69 INFO2("%s%s",msg,buff);
72 /** @brief ensures that a userdata on the stack is a task and returns the pointer inside the userdata */
73 static m_task_t checkTask (lua_State *L,int index) {
75 luaL_checktype(L,index,LUA_TTABLE);
76 lua_getfield(L,index,"__simgrid_task");
77 pi = (m_task_t*)luaL_checkudata(L,-1,TASK_MODULE_NAME);
79 luaL_typerror(L,index,TASK_MODULE_NAME);
82 luaL_error(L,"null Task");
86 /* ********************************************************************************* */
87 /* wrapper functions */
88 /* ********************************************************************************* */
91 * A task is either something to compute somewhere, or something to exchange between two hosts (or both).
92 * It is defined by a computing amount and a message size.
100 * Construct an new task with the specified processing amount and amount
103 * @param name Task's name
105 * @param computeDuration A value of the processing amount (in flop) needed to process the task.
106 * If 0, then it cannot be executed with the execute() method.
107 * This value has to be >= 0.
109 * @param messageSize A value of amount of data (in bytes) needed to transfert this task.
110 * If 0, then it cannot be transfered with the get() and put() methods.
111 * This value has to be >= 0.
113 static int Task_new(lua_State* L) {
114 const char *name=luaL_checkstring(L,1);
115 int comp_size = luaL_checkint(L,2);
116 int msg_size = luaL_checkint(L,3);
117 m_task_t msg_task = MSG_task_create(name,comp_size,msg_size,NULL);
118 lua_newtable (L); /* create a table, put the userdata on top of it */
119 m_task_t *lua_task = (m_task_t*)lua_newuserdata(L,sizeof(m_task_t));
120 *lua_task = msg_task;
121 luaL_getmetatable(L,TASK_MODULE_NAME);
122 lua_setmetatable(L,-2);
123 lua_setfield (L, -2, "__simgrid_task"); /* put the userdata as field of the table */
124 /* remove the args from the stack */
131 static int Task_get_name(lua_State *L) {
132 m_task_t tk = checkTask(L,-1);
133 lua_pushstring(L,MSG_task_get_name(tk));
137 static int Task_computation_duration(lua_State *L){
138 m_task_t tk = checkTask(L,-1);
139 lua_pushnumber(L,MSG_task_get_compute_duration (tk));
143 static int Task_execute(lua_State *L){
144 m_task_t tk = checkTask(L,-1);
145 int res = MSG_task_execute(tk);
146 lua_pushnumber(L,res);
150 static int Task_destroy(lua_State *L) {
151 m_task_t tk = checkTask(L,-1);
152 int res = MSG_task_destroy(tk);
153 lua_pushnumber(L,res);
157 static int Task_send(lua_State *L) {
158 //stackDump("send ",L);
159 m_task_t tk = checkTask(L,-2);
160 const char *mailbox = luaL_checkstring(L,-1);
161 lua_pop(L,1); // remove the string so that the task is on top of it
162 MSG_task_set_data(tk,L); // Copy my stack into the task, so that the receiver can copy the lua task directly
163 MSG_error_t res = MSG_task_send(tk,mailbox);
164 while (MSG_task_get_data(tk)!=NULL) // Don't mess up with my stack: the receiver didn't copy the data yet
165 MSG_process_sleep(0); // yield
167 if (res != MSG_OK) switch(res) {
169 ERROR0("MSG_task_send failed : Timeout");
171 case MSG_TRANSFER_FAILURE :
172 ERROR0("MSG_task_send failed : Transfer Failure");
174 case MSG_HOST_FAILURE :
175 ERROR0("MSG_task_send failed : Host Failure ");
178 ERROR0("MSG_task_send failed : Unexpected error , please report this bug");
184 static int Task_recv(lua_State *L) {
186 const char *mailbox = luaL_checkstring(L,-1);
187 MSG_error_t res = MSG_task_receive(&tk,mailbox);
189 lua_State *sender_stack = MSG_task_get_data(tk);
190 lua_xmove(sender_stack,L,1); // copy the data directly from sender's stack
191 MSG_task_set_data(tk,NULL);
193 if(res != MSG_OK) switch(res){
195 ERROR0("MSG_task_receive failed : Timeout");
197 case MSG_TRANSFER_FAILURE :
198 ERROR0("MSG_task_receive failed : Transfer Failure");
200 case MSG_HOST_FAILURE :
201 ERROR0("MSG_task_receive failed : Host Failure ");
204 ERROR0("MSG_task_receive failed : Unexpected error , please report this bug");
211 static const luaL_reg Task_methods[] = {
213 {"name", Task_get_name},
214 {"computation_duration", Task_computation_duration},
215 {"execute", Task_execute},
216 {"destroy", Task_destroy},
221 static int Task_gc(lua_State *L) {
222 m_task_t tk=checkTask(L,-1);
223 if (tk) MSG_task_destroy(tk);
227 static int Task_tostring(lua_State *L) {
228 lua_pushfstring(L, "Task :%p",lua_touserdata(L,1));
232 static const luaL_reg Task_meta[] = {
234 {"__tostring", Task_tostring},
241 static m_host_t checkHost (lua_State *L,int index) {
243 luaL_checktype(L,index,LUA_TTABLE);
244 lua_getfield(L,index,"__simgrid_host");
245 pi = (m_host_t*)luaL_checkudata(L,-1,HOST_MODULE_NAME);
247 luaL_typerror(L,index,HOST_MODULE_NAME);
250 luaL_error(L,"null Host");
255 static int Host_get_by_name(lua_State *L)
257 const char *name=luaL_checkstring(L,1);
258 DEBUG0("Getting Host from name...");
259 m_host_t msg_host = MSG_get_host_by_name(name);
262 luaL_error(L,"null Host : MSG_get_host_by_name failled");
264 lua_newtable (L); /* create a table, put the userdata on top of it */
265 m_host_t *lua_host = (m_host_t*)lua_newuserdata(L,sizeof(m_host_t));
266 *lua_host = msg_host;
267 luaL_getmetatable(L,HOST_MODULE_NAME);
268 lua_setmetatable(L,-2);
269 lua_setfield (L, -2, "__simgrid_host"); /* put the userdata as field of the table */
270 /* remove the args from the stack */
276 static int Host_get_name(lua_State *L) {
277 m_host_t ht = checkHost(L,-1);
278 lua_pushstring(L,MSG_host_get_name(ht));
282 static int Host_number(lua_State *L) {
283 lua_pushnumber(L,MSG_get_host_number());
287 static int Host_at(lua_State *L)
289 int index = luaL_checkinteger(L,1);
290 m_host_t host = MSG_get_host_table()[index-1]; // lua indexing start by 1 (lua[1] <=> C[0])
291 lua_newtable (L); /* create a table, put the userdata on top of it */
292 m_host_t *lua_host = (m_host_t*)lua_newuserdata(L,sizeof(m_host_t));
294 luaL_getmetatable(L,HOST_MODULE_NAME);
295 lua_setmetatable(L,-2);
296 lua_setfield (L, -2, "__simgrid_host"); /* put the userdata as field of the table */
301 /*****************************************************************************************
302 * BYPASS XML SURF Methods *
303 ***************************
304 ***************************
305 ******************************************************************************************/
306 #include "surf/surfxml_parse.h" /* to override surf_parse and bypass the parser */
307 #include "surf/surf_private.h"
308 typedef struct t_host_attr
311 // Mandatory attributes
314 // Optional attributes
316 const char *power_trace;
318 const char *state_trace;
319 //deployment attribute
320 const char* function;
321 xbt_dynar_t args_list;
322 }host_attr,*p_host_attr;
324 typedef struct t_link_attr
329 }link_attr,*p_link_attr;
331 typedef struct t_route_attr
335 xbt_dynar_t links_id;
337 }route_attr,*p_route_attr;
339 //using xbt_dynar_t :
340 static xbt_dynar_t host_list_d ;
341 static xbt_dynar_t link_list_d ;
342 static xbt_dynar_t route_list_d ;
347 /*FIXME : still have to use a dictionary as argument make it possible to
348 consider some arguments as optional and removes the importance of the
351 static void create_host(const char* id,double power_peak,double power_sc,
352 const char* power_tr,int state_init,
353 const char* state_tr)
356 double power_scale = 1.0;
357 tmgr_trace_t power_trace = NULL;
358 e_surf_resource_state_t state_initial;
359 tmgr_trace_t state_trace;
361 power_scale = power_sc;
363 state_initial = SURF_RESOURCE_ON;
365 state_init = SURF_RESOURCE_OFF;
367 power_trace = tmgr_trace_new(power_tr);
369 power_trace = tmgr_trace_new("");
371 state_trace = tmgr_trace_new(state_tr);
373 state_trace = tmgr_trace_new("");
374 current_property_set = xbt_dict_new();
375 surf_host_create_resource(xbt_strdup(id), power_peak, power_scale,
376 power_trace, state_initial, state_trace, current_property_set);
380 static int Host_new(lua_State *L)
383 if(xbt_dynar_is_empty(host_list_d))
384 host_list_d = xbt_dynar_new(sizeof(p_host_attr), &xbt_free_ref);
388 const char *power_trace;
389 const char *state_trace;
390 double power,power_scale;
392 //get values from the table passed as argument
393 if (lua_istable(L,-1)) {
396 lua_pushstring(L,"id");
397 lua_gettable(L, -2 );
398 id = lua_tostring(L,-1);
402 lua_pushstring(L,"power");
403 lua_gettable(L, -2 );
404 power = lua_tonumber(L,-1);
408 lua_pushstring(L,"power_scale");
409 lua_gettable(L, -2 );
410 power_scale = lua_tonumber(L,-1);
414 lua_pushstring(L,"power_trace");
415 lua_gettable(L, -2 );
416 power_trace = lua_tostring(L,-1);
420 lua_pushstring(L,"state_initial");
421 lua_gettable(L, -2 );
422 state_initial = lua_tonumber(L,-1);
426 lua_pushstring(L,"state_trace");
427 lua_gettable(L, -2 );
428 state_trace = lua_tostring(L,-1);
432 ERROR0("Bad Arguments to create host, Should be a table with named arguments");
436 host = malloc(sizeof(host_attr));
438 host->power_peak = power;
439 host->power_scale = power_scale;
440 host->power_trace = power_trace;
441 host->state_initial = state_initial;
442 host->state_trace = state_trace;
443 host->function = NULL;
444 xbt_dynar_push(host_list_d, &host);
451 static int Link_new(lua_State *L) // (id,bandwidth,latency)
453 if(xbt_dynar_is_empty(link_list_d))
454 link_list_d = xbt_dynar_new(sizeof(p_link_attr), &xbt_free_ref);
457 double bandwidth,latency;
458 //get values from the table passed as argument
459 if (lua_istable(L,-1)) {
461 lua_pushstring(L,"id");
462 lua_gettable(L, -2 );
463 id = lua_tostring(L,-1);
466 // get bandwidth value
467 lua_pushstring(L,"bandwidth");
468 lua_gettable(L, -2 );
469 bandwidth = lua_tonumber(L,-1);
473 lua_pushstring(L,"latency");
474 lua_gettable(L, -2 );
475 latency = lua_tonumber(L,-1);
479 ERROR0("Bad Arguments to create link, Should be a table with named arguments");
483 p_link_attr link = malloc(sizeof(link_attr));
485 link->bandwidth = bandwidth;
486 link->latency = latency;
487 xbt_dynar_push(link_list_d,&link);
491 static int Route_new(lua_State *L) // (src_id,dest_id,links_number,link_table)
493 if(xbt_dynar_is_empty(route_list_d))
494 route_list_d = xbt_dynar_new(sizeof(p_route_attr), &xbt_free_ref);
496 const char * link_id;
497 p_route_attr route = malloc(sizeof(route_attr));
498 route->src_id = luaL_checkstring(L,1);
499 route->dest_id = luaL_checkstring(L,2);
500 route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
502 while (lua_next(L,3) != 0) {
503 link_id = lua_tostring(L, -1);
504 xbt_dynar_push(route->links_id, &link_id);
505 DEBUG2("index = %f , Link_id = %s \n",lua_tonumber(L, -2),lua_tostring(L, -1));
510 //add route to platform's route list
511 xbt_dynar_push(route_list_d,&route);
515 static int Host_set_function(lua_State *L) //(host,function,nb_args,list_args)
517 // look for the index of host in host_list
518 const char *host_id = luaL_checkstring(L,1);
519 const char* argument;
523 xbt_dynar_foreach(host_list_d,i,p_host)
525 if(p_host->id == host_id)
527 p_host->function = luaL_checkstring(L,2);
528 p_host->args_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
529 // fill the args list
532 while (lua_next(L,3) != 0) {
533 argument = lua_tostring(L, -1);
534 xbt_dynar_push(p_host->args_list, &argument);
535 DEBUG2("index = %f , Arg_id = %s \n",lua_tonumber(L, -2),lua_tostring(L, -1));
543 ERROR1("Host : %s Not Fount !!",host_id);
548 * surf parse bypass platform
550 static int surf_parse_bypass_platform()
558 p_route_attr p_route;
560 static int AX_ptr = 0;
561 static int surfxml_bufferstack_size = 2048;
563 /* FIXME allocating memory for the buffer, I think 2kB should be enough */
564 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
567 SURFXML_BUFFER_SET(platform_version, "2");
568 SURFXML_START_TAG(platform);
572 xbt_dynar_foreach(host_list_d,i,p_host)
576 create_host(p_host->id,p_host->power_peak,p_host->power_scale,p_host->power_trace,
577 p_host->state_initial,p_host->state_trace);
578 //add to routing model host list
579 surf_route_add_host((char*)p_host->id);
582 SURFXML_BUFFER_SET(host_id,p_host->id);
583 sprintf(buffer,"%f",p_host->power_peak);
584 SURFXML_BUFFER_SET(host_power,buffer);
585 SURFXML_BUFFER_SET(host_availability, "1.0");
586 SURFXML_BUFFER_SET(host_availability_file, "");
587 A_surfxml_host_state = A_surfxml_host_state_ON;
588 SURFXML_BUFFER_SET(host_state_file, "");
589 SURFXML_BUFFER_SET(host_interference_send, "1.0");
590 SURFXML_BUFFER_SET(host_interference_recv, "1.0");
591 SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
592 SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
593 SURFXML_START_TAG(host);
594 SURFXML_END_TAG(host);
599 xbt_dynar_foreach(link_list_d,i,p_link)
602 surf_link_create_resouce((char*)p_link->id,p_link->bandwidth,p_link->latency);
605 SURFXML_BUFFER_SET(link_id,p_link->id);
606 sprintf(buffer,"%f",p_link->bandwidth);
607 SURFXML_BUFFER_SET(link_bandwidth,buffer);
608 SURFXML_BUFFER_SET(link_bandwidth_file, "");
609 sprintf(buffer,"%f",p_link->latency);
610 SURFXML_BUFFER_SET(link_latency,buffer);
611 SURFXML_BUFFER_SET(link_latency_file, "");
612 A_surfxml_link_state = A_surfxml_link_state_ON;
613 SURFXML_BUFFER_SET(link_state_file, "");
614 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
615 SURFXML_START_TAG(link);
616 SURFXML_END_TAG(link);
621 xbt_dynar_foreach(route_list_d,i,p_route)
624 surf_route_set_resource((char*)p_route->src_id,(char*)p_route->dest_id,p_route->links_id,0);
627 SURFXML_BUFFER_SET(route_src,p_route->src_id);
628 SURFXML_BUFFER_SET(route_dst,p_route->dest_id);
629 SURFXML_BUFFER_SET(route_impact_on_src, "0.0");
630 SURFXML_BUFFER_SET(route_impact_on_dst, "0.0");
631 SURFXML_BUFFER_SET(route_impact_on_src_with_other_recv, "0.0");
632 SURFXML_BUFFER_SET(route_impact_on_dst_with_other_send, "0.0");
633 SURFXML_START_TAG(route);
635 xbt_dynar_foreach(p_route->links_id,j,link_id)
637 SURFXML_BUFFER_SET(link_c_ctn_id,link_id);
638 SURFXML_START_TAG(link_c_ctn);
639 SURFXML_END_TAG(link_c_ctn);
643 SURFXML_END_TAG(route);
648 SURFXML_END_TAG(platform);
651 free(surfxml_bufferstack);
652 return 0; // must return 0 ?!!
656 * surf parse bypass application
658 static int surf_parse_bypass_application()
664 static int surfxml_bufferstack_size = 2048;
665 /* FIXME ( should be manual )allocating memory to the buffer, I think 2MB should be enough */
666 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
669 xbt_dynar_foreach(host_list_d,i,p_host)
672 MSG_set_function(p_host->id,p_host->function,p_host->args_list);
677 SURFXML_BUFFER_SET(platform_version, "2");
678 SURFXML_START_TAG(platform);
679 xbt_dynar_foreach(host_list_d,i,p_host)
683 SURFXML_BUFFER_SET(process_host, p_host->id);
684 SURFXML_BUFFER_SET(process_function, p_host->function);
685 SURFXML_BUFFER_SET(process_start_time, "-1.0");
686 SURFXML_BUFFER_SET(process_kill_time, "-1.0");
687 SURFXML_START_TAG(process);
689 xbt_dynar_foreach(p_host->args_list,j,arg)
691 SURFXML_BUFFER_SET(argument_value,arg);
692 SURFXML_START_TAG(argument);
693 SURFXML_END_TAG(argument);
695 SURFXML_END_TAG(process);
699 SURFXML_END_TAG(platform);
701 free(surfxml_bufferstack);
705 //***********Register Methods *******************************************//
709 static const luaL_reg Host_methods[] = {
710 {"getByName", Host_get_by_name},
711 {"name", Host_get_name},
712 {"number", Host_number},
714 // Bypass XML Methods
716 {"setFunction", Host_set_function},
720 static int Host_gc(lua_State *L)
722 m_host_t ht = checkHost(L,-1);
727 static int Host_tostring(lua_State *L)
729 lua_pushfstring(L,"Host :%p",lua_touserdata(L,1));
733 static const luaL_reg Host_meta[] = {
735 {"__tostring", Host_tostring},
742 static const luaL_reg Link_methods[] = {
749 static const luaL_reg Route_methods[] ={
755 * Environment related
758 extern lua_State *simgrid_lua_state;
760 static int run_lua_code(int argc,char **argv) {
761 DEBUG1("Run lua code %s",argv[0]);
762 lua_State *L = lua_newthread(simgrid_lua_state);
763 int ref = luaL_ref(simgrid_lua_state, LUA_REGISTRYINDEX); // protect the thread from being garbage collected
766 /* Start the co-routine */
767 lua_getglobal(L,argv[0]);
768 xbt_assert1(lua_isfunction(L,-1),
769 "The lua function %s does not seem to exist",argv[0]);
771 // push arguments onto the stack
774 lua_pushstring(L,argv[i]);
776 // Call the function (in resume)
777 xbt_assert2(lua_pcall(L, argc-1, 1, 0) == 0,
778 "error running function `%s': %s",argv[0], lua_tostring(L, -1));
780 /* retrieve result */
781 if (lua_isnumber(L, -1)) {
782 res = lua_tonumber(L, -1);
783 lua_pop(L, 1); /* pop returned value */
787 luaL_unref(simgrid_lua_state,LUA_REGISTRYINDEX,ref );
788 DEBUG1("Execution of lua code %s is over", (argv ? argv[0] : "(null)"));
791 static int launch_application(lua_State *L) {
792 const char * file = luaL_checkstring(L,1);
793 MSG_function_register_default(run_lua_code);
794 MSG_launch_application(file);
797 #include "simix/simix.h" //FIXME: KILLME when debugging on simix internals become useless
798 static int create_environment(lua_State *L) {
799 const char *file = luaL_checkstring(L,1);
800 DEBUG1("Loading environment file %s",file);
801 MSG_create_environment(file);
802 smx_host_t *hosts = SIMIX_host_get_table();
804 for (i=0;i<SIMIX_host_get_number();i++) {
805 DEBUG1("We have an host %s", SIMIX_host_get_name(hosts[i]));
811 static int debug(lua_State *L) {
812 const char *str = luaL_checkstring(L,1);
816 static int info(lua_State *L) {
817 const char *str = luaL_checkstring(L,1);
821 static int run(lua_State *L) {
825 static int clean(lua_State *L) {
833 static int register_platform(lua_State *L)
835 /* Tell Simgrid we dont wanna use its parser*/
836 surf_parse = surf_parse_bypass_platform;
837 MSG_create_environment(NULL);
841 static int register_application(lua_State *L)
843 MSG_function_register_default(run_lua_code);
844 surf_parse = surf_parse_bypass_application;
845 MSG_launch_application(NULL);
849 static const luaL_Reg simgrid_funcs[] = {
850 { "create_environment", create_environment},
851 { "launch_application", launch_application},
857 { "platform", create_environment},
858 { "application", launch_application},
859 /* methods to bypass XML parser*/
860 { "register_platform",register_platform},
861 { "register_application",register_application},
865 /* ********************************************************************************* */
866 /* module management functions */
867 /* ********************************************************************************* */
869 extern const char*xbt_ctx_factory_to_use; /*Hack: let msg load directly the right factory */
871 #define LUA_MAX_ARGS_COUNT 10 /* maximum amount of arguments we can get from lua on command line */
873 int luaopen_simgrid(lua_State* L); // Fuck gcc: we don't need that prototype
874 int luaopen_simgrid(lua_State* L) {
875 //xbt_ctx_factory_to_use = "lua";
877 char **argv=malloc(sizeof(char*)*LUA_MAX_ARGS_COUNT);
879 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? */
880 /* Get the command line arguments from the lua interpreter */
881 lua_getglobal(L,"arg");
882 xbt_assert1(lua_istable(L,-1),"arg parameter is not a table but a %s",lua_typename(L,-1));
886 lua_pushinteger(L,argc-2);
888 if (lua_isnil(L,-1)) {
891 xbt_assert1(lua_isstring(L,-1),"argv[%d] got from lua is no string",argc-1);
892 xbt_assert2(argc<LUA_MAX_ARGS_COUNT,
893 "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",
894 __FILE__,LUA_MAX_ARGS_COUNT-1);
895 argv[argc-1] = (char*)luaL_checkstring(L,-1);
897 DEBUG1("Got command line argument %s from lua",argv[argc-1]);
902 /* Initialize the MSG core */
903 MSG_global_init(&argc,argv);
904 DEBUG1("Still %d arguments on command line",argc); // FIXME: update the lua's arg table to reflect the changes from SimGrid
906 /* register the core C functions to lua */
907 luaL_register(L, "simgrid", simgrid_funcs);
908 /* register the task methods to lua */
909 luaL_openlib(L,TASK_MODULE_NAME,Task_methods,0); //create methods table,add it to the globals
910 luaL_newmetatable(L,TASK_MODULE_NAME); //create metatable for Task,add it to the Lua registry
911 luaL_openlib(L,0,Task_meta,0);// fill metatable
912 lua_pushliteral(L,"__index");
913 lua_pushvalue(L,-3); //dup methods table
914 lua_rawset(L,-3); //matatable.__index = methods
915 lua_pushliteral(L,"__metatable");
916 lua_pushvalue(L,-3); //dup methods table
917 lua_rawset(L,-3); //hide metatable:metatable.__metatable = methods
918 lua_pop(L,1); //drop metatable
920 /* register the hosts methods to lua*/
921 luaL_openlib(L,HOST_MODULE_NAME,Host_methods,0);
922 luaL_newmetatable(L,HOST_MODULE_NAME);
923 luaL_openlib(L,0,Host_meta,0);
924 lua_pushliteral(L,"__index");
927 lua_pushliteral(L,"__metatable");
932 /* register the links methods to lua*/
933 luaL_openlib(L,LINK_MODULE_NAME,Link_methods,0);
934 luaL_newmetatable(L,LINK_MODULE_NAME);
937 /*register the routes methods to lua*/
938 luaL_openlib(L,ROUTE_MODULE_NAME,Route_methods,0);
939 luaL_newmetatable(L,LINK_MODULE_NAME);
942 /* Keep the context mechanism informed of our lua world today */
943 simgrid_lua_state = L;