void sglua_register_comm_functions(lua_State* L)
{
/* create a table simgrid.comm and fill it with com functions */
- lua_newtable(L);
- luaL_setfuncs(L, comm_functions, 0);
- lua_setglobal(L, COMM_MODULE_NAME);
- /*luaL_openlib(L, COMM_MODULE_NAME, comm_functions, 0);*/
- /* simgrid.comm */
-
- /* create the metatable for comms, add it to the Lua registry */
- luaL_newmetatable(L, COMM_MODULE_NAME);
- /* simgrid.comm mt */
+ lua_getglobal(L, "simgrid"); /* simgrid */
+ luaL_newlib(L, comm_functions); /* simgrid simgrid.comm */
+ lua_setfield(L, -2, "comm"); /* simgrid */
+ lua_getfield(L, -1, "host"); /* simgrid simgrid.comm */
+
+ /* create the metatable for comm, add it to the Lua registry */
+ luaL_newmetatable(L, COMM_MODULE_NAME); /* simgrid simgrid.comm mt */
+
/* fill the metatable */
- luaL_setfuncs(L, comm_meta, 0);
- luaL_setmetatable(L, COMM_MODULE_NAME);
- /*luaL_openlib(L, NULL, comm_meta, 0);*/
- /* simgrid.comm mt */
- /*lua_pushvalue(L, -2);*/
- /* simgrid.comm mt simgrid.comm */
+ luaL_setfuncs(L, comm_meta, 0); /* simgrid simgrid.comm mt */
+
+ /**
+ * Copy the table and push it onto the stack.
+ * Required for the lua_setfield call below.
+ */
+ lua_getfield(L, -3, "comm"); /* simgrid simgrid.comm mt simgrid.comm */
+
/* metatable.__index = simgrid.comm
- * we put the comm functions inside the comm itself:
+ * we put the comm functions inside the comm userdata itself:
* this allows to write my_comm:method(args) for
* simgrid.comm.method(my_comm, args) */
- lua_setfield(L, -2, "__index");
- /* simgrid.comm mt */
- lua_pop(L, 2);
- /* -- */
+ lua_setfield(L, -2, "__index"); /* simgrid simgrid.comm mt */
+
+ lua_setmetatable(L, -2); /* simgrid simgrid.comm */
+ lua_pop(L, 2); /* -- */
}
XBT_DEBUG("Getting Host from name...");
msg_host_t msg_host = MSG_host_by_name(name);
if (!msg_host) {
- luaL_error(L, "null Host : MSG_get_host_by_name failed");
+ XBT_ERROR("MSG_get_host_by_name failed, requested hostname: %s", name);
}
lua_newtable(L); /* create a table, put the userdata on top of it */
msg_host_t *lua_host = (msg_host_t *) lua_newuserdata(L, sizeof(msg_host_t));
lua_getglobal(L, "simgrid"); /* simgrid */
luaL_newlib(L, host_functions); /* simgrid simgrid.host */
lua_setfield(L, -2, "host"); /* simgrid */
+ lua_getfield(L, -1, "host"); /* simgrid simgrid.host */
/* create the metatable for host, add it to the Lua registry */
- luaL_newmetatable(L, HOST_MODULE_NAME); /* simgrid mt */
+ luaL_newmetatable(L, HOST_MODULE_NAME); /* simgrid simgrid.host mt */
/* fill the metatable */
- luaL_setfuncs(L, host_meta, 0); /* simgrid mt */
+ luaL_setfuncs(L, host_meta, 0); /* simgrid simgrid.host mt */
/**
* Copy the table and push it onto the stack.
* Required for the lua_setfield call below.
*/
- lua_getfield(L, -2, "host"); /* simgrid mt simgrid.host */
+ lua_getfield(L, -3, "host"); /* simgrid simgrid.host mt simgrid.host */
/* metatable.__index = simgrid.host
* we put the host functions inside the host userdata itself:
* this allows to write my_host:method(args) for
* simgrid.host.method(my_host, args) */
- lua_setfield(L, -2, "__index"); /* simgrid mt */
+ lua_setfield(L, -2, "__index"); /* simgrid simgrid.host mt */
- lua_setmetatable(L, -2); /* simgrid */
- lua_pop(L, 1);
+ lua_setmetatable(L, -2); /* simgrid simgrid.host */
+ lua_pop(L, 2); /* -- */
}
*/
void sglua_register_platf_functions(lua_State* L)
{
- lua_newtable(L);
- luaL_setfuncs(L, platf_functions, 0);
- lua_pushvalue(L, -1);
- lua_setglobal(L, PLATF_MODULE_NAME);
- /*luaL_openlib(L, PLATF_MODULE_NAME, platf_functions, 0);*/
- /* simgrid.platf */
- lua_pop(L, 1);
+ lua_getglobal(L, "simgrid"); /* simgrid */
+ luaL_newlib(L, platf_functions); /* simgrid simgrid.platf */
+ lua_setfield(L, -2, "platf"); /* simgrid */
+
+ lua_pop(L, 1); /* -- */
}
*/
void sglua_register_process_functions(lua_State* L)
{
- lua_newtable(L);
- luaL_setfuncs(L, process_functions, 0);
- lua_pushvalue(L, -1);
- lua_setglobal(L, PROCESS_MODULE_NAME);
- /*luaL_openlib(L, PROCESS_MODULE_NAME, process_functions, 0);*/
- /* simgrid.process */
- lua_pop(L, 1);
+ lua_getglobal(L, "simgrid"); /* simgrid */
+ luaL_newlib(L, process_functions); /* simgrid simgrid.process */
+ lua_setfield(L, -2, "process"); /* simgrid */
+ lua_pop(L, 1); /* -- */
}
void sglua_register_task_functions(lua_State* L)
{
/* create a table simgrid.task and fill it with task functions */
- lua_newtable(L);
- luaL_setfuncs(L, task_functions, 0);
- lua_pushvalue(L, -1);
- lua_setglobal(L, TASK_MODULE_NAME);
- /*luaL_openlib(L, TASK_MODULE_NAME, task_functions, 0);*/
- /* simgrid.task */
+ lua_getglobal(L, "simgrid"); /* simgrid */
+ luaL_newlib(L, task_functions); /* simgrid simgrid.task */
+ lua_setfield(L, -2, "task"); /* simgrid */
+ lua_getfield(L, -1, "task"); /* simgrid simgrid.task */
/* create the metatable for tasks, add it to the Lua registry */
- luaL_newmetatable(L, TASK_MODULE_NAME);
- /* simgrid.task mt */
+ luaL_newmetatable(L, TASK_MODULE_NAME); /* simgrid simgrid.task mt */
+
/* fill the metatable */
- luaL_setfuncs(L, task_meta, 0);
- /*luaL_openlib(L, NULL, task_meta, 0);*/
- /* simgrid.task mt */
- lua_pushvalue(L, -2);
- /* simgrid.task mt simgrid.task */
+ luaL_setfuncs(L, task_meta, 0); /* simgrid simgrid.task mt */
+ lua_getfield(L, -3, "task"); /* simgrid simgrid.task mt simgrid.task */
+
/* metatable.__index = simgrid.task
* we put the task functions inside the task itself:
* this allows to write my_task:method(args) for
* simgrid.task.method(my_task, args) */
- lua_setfield(L, -2, "__index");
- /* simgrid.task mt */
- lua_pop(L, 2);
- /* -- */
+ lua_setfield(L, -2, "__index"); /* simgrid simgrid.task mt */
+
+ lua_setmetatable(L, -2); /* simgrid simgrid.task */
+ lua_pop(L, 2); /* -- */
/* set up MSG to copy Lua tasks between states */
MSG_task_set_copy_callback(task_copy_callback);
static void sglua_register_core_functions(lua_State *L)
{
/* register the core C functions to lua */
- /*luaL_Register(L, "simgrid", simgrid_functions);*/
- lua_newtable(L);
- luaL_setfuncs(L, simgrid_functions, 0);
- lua_pushvalue(L, -1);
- lua_setglobal(L, "simgrid");
-
- /* simgrid */
+ luaL_newlib(L, simgrid_functions); /* simgrid */
+ lua_pushvalue(L, -1); /* simgrid simgrid */
+ lua_setglobal(L, "simgrid"); /* simgrid */
/* set a finalizer that cleans simgrid, by adding to the simgrid module a
* dummy userdata whose __gc metamethod calls MSG_clean() */
- lua_newuserdata(L, sizeof(void*));
- /* simgrid udata */
- lua_newtable(L);
- /* simgrid udata mt */
- lua_pushcfunction(L, simgrid_gc);
- /* simgrid udata mt simgrid_gc */
- lua_setfield(L, -2, "__gc");
- /* simgrid udata mt */
- lua_setmetatable(L, -2);
- /* simgrid udata */
- lua_setfield(L, -2, "__simgrid_loaded");
- /* simgrid */
- lua_pop(L, 1);
- /* -- */
+ lua_newuserdata(L, sizeof(void*)); /* simgrid udata */
+ lua_newtable(L); /* simgrid udata mt */
+ lua_pushcfunction(L, simgrid_gc); /* simgrid udata mt simgrid_gc */
+ lua_setfield(L, -2, "__gc"); /* simgrid udata mt */
+ lua_setmetatable(L, -2); /* simgrid udata */
+ lua_setfield(L, -2, "__simgrid_loaded"); /* simgrid */
+ lua_pop(L, 1); /* -- */
}
/**