}
}
-static const luaL_reg comm_functions[] = {
+static const luaL_Reg comm_functions[] = {
{"wait", l_comm_wait},
{"test", l_comm_test},
/* TODO waitany, testany */
/**
* \brief Metamethods of the comm userdata.
*/
-static const luaL_reg comm_meta[] = {
+static const luaL_Reg comm_meta[] = {
{"__gc", l_comm_gc},
{NULL, NULL}
};
*/
void sglua_register_comm_functions(lua_State* L)
{
- /* create a table simgrid.com and fill it with com functions */
- luaL_openlib(L, COMM_MODULE_NAME, comm_functions, 0);
+ /* 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 */
/* fill the metatable */
- luaL_openlib(L, NULL, comm_meta, 0);
+ 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);
+ /*lua_pushvalue(L, -2);*/
/* simgrid.comm mt simgrid.comm */
/* metatable.__index = simgrid.comm
* we put the comm functions inside the comm itself:
lua_getfield(L, index, "__simgrid_host");
pi = (msg_host_t *) luaL_checkudata(L, lua_gettop(L), HOST_MODULE_NAME);
if (pi == NULL)
- luaL_typerror(L, index, HOST_MODULE_NAME);
+ XBT_ERROR("luaL_checkudata() returned NULL");
ht = *pi;
if (!ht)
luaL_error(L, "null Host");
return 0;
}
-static const luaL_reg host_functions[] = {
+static const luaL_Reg host_functions[] = {
{"get_by_name", l_host_get_by_name},
{"name", l_host_get_name},
{"number", l_host_number},
return 1;
}
-static const luaL_reg host_meta[] = {
+static const luaL_Reg host_meta[] = {
{"__tostring", l_host_tostring},
{0, 0}
};
void sglua_register_host_functions(lua_State* L)
{
/* create a table simgrid.host and fill it with host functions */
- luaL_openlib(L, HOST_MODULE_NAME, host_functions, 0);
+ lua_newtable(L);
+ luaL_setfuncs(L, host_functions, 0);
+ // Not sure we really need this one here...
+ /*lua_pushvalue(L, -1);*/
+ /*lua_setglobal(L, HOST_MODULE_NAME);*/
+
+ /*luaL_openlib(L, HOST_MODULE_NAME, host_functions, 0);*/
/* simgrid.host */
/* create the metatable for host, add it to the Lua registry */
luaL_newmetatable(L, HOST_MODULE_NAME);
/* simgrid.host mt */
/* fill the metatable */
- luaL_openlib(L, NULL, host_meta, 0);
+ luaL_setfuncs(L, host_meta, 0);
+ /*luaL_openlib(L, NULL, host_meta, 0);*/
/* simgrid.host mt */
+ /**
+ * Copy the table and push it onto the stack.
+ * Required for the lua_setfield call below.
+ */
lua_pushvalue(L, -2);
/* 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");
+ lua_setfield(L, -1, "__index");
/* simgrid.host mt */
- lua_pop(L, 2);
+ lua_setmetatable(L, -2);
/* -- */
}
/* simgrid.platf API */
/* ********************************************************************************* */
-static const luaL_reg platf_functions[] = {
+static const luaL_Reg platf_functions[] = {
{"open", console_open},
{"close", console_close},
{"AS_open", console_AS_open},
*/
void sglua_register_platf_functions(lua_State* L)
{
- luaL_openlib(L, PLATF_MODULE_NAME, platf_functions, 0);
+ 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);
}
}
}
-static const luaL_reg process_functions[] = {
+static const luaL_Reg process_functions[] = {
{"sleep", l_process_sleep},
/* TODO: self, create, kill, suspend, is_suspended, resume, get_name,
* get_pid, get_ppid, migrate
*/
void sglua_register_process_functions(lua_State* L)
{
- luaL_openlib(L, PROCESS_MODULE_NAME, process_functions, 0);
+ 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);
}
buffer.size = 0;
buffer.data = xbt_new(char, buffer.capacity);
- /* copy the binary chunk from src into a buffer */
- XBT_ATTRIB_UNUSED int error = lua_dump(src, sglua_memory_writer, &buffer);
+ /* copy the binary chunk from src into a buffer
+ * c.heinrich: Added parameter TRUE for Lua 5.3 - this strips all debug
+ * information from the function.
+ */
+ // Was before merge: XBT_GNUC_UNUSED and was replaced with XBT_ATTRIB_UNUSED
+ XBT_ATTRIB_UNUSED int error = lua_dump(src, sglua_memory_writer, &buffer, TRUE);
xbt_assert(!error, "Failed to dump the function from the source state: error %d",
error);
XBT_DEBUG("Fonction dumped: %zu bytes", buffer.size);
/* copy the data */
/* src: ... udata
dst: ... */
- size_t size = lua_objlen(src, -1);
+ size_t size = lua_rawlen(src, -1);
void* src_block = lua_touserdata(src, -1);
void* dst_block = lua_newuserdata(dst, size);
/* dst: ... udata */
/* want a global or a registry value? */
int pseudo_index;
- if (lua_equal(L, 1, LUA_REGISTRYINDEX)) {
+ if (lua_compare(L, 1, LUA_REGISTRYINDEX, LUA_OPEQ)) {
/* registry */
pseudo_index = LUA_REGISTRYINDEX;
XBT_DEBUG("Will get the value from the registry of maestro");
}
else {
/* global */
- pseudo_index = LUA_GLOBALSINDEX;
+ pseudo_index = lua_getfield(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
XBT_DEBUG("Will get the value from the globals of maestro");
}
lua_setmetatable(L, -2); /* thread newenv mt reg */
lua_pop(L, 1); /* thread newenv mt */
lua_setmetatable(L, -2); /* thread newenv */
- lua_setfenv(L, -2); /* thread */
+ // TODO c.heinrich This needs to be re-implemented
+ /*lua_setfenv(L, -2); [> thread <]*/
lua_pop(L, 1); /* -- */
/* create the table of known tables from maestro */
{
XBT_DEBUG("Task new");
const char* name = luaL_checkstring(L, 1);
- int comp_size = luaL_checkint(L, 2);
- int msg_size = luaL_checkint(L, 3);
+ int comp_size = (int) luaL_checkinteger(L, 2);
+ int msg_size = (int) luaL_checkinteger(L, 3);
/* name comp comm */
lua_settop(L, 0);
/* -- */
return 1;
}
-static const luaL_reg task_functions[] = {
+static const luaL_Reg task_functions[] = {
{"new", l_task_new},
{"get_name", l_task_get_name},
{"get_computation_duration", l_task_get_computation_duration},
/**
* \brief Metamethods of both a task table and the userdata inside it.
*/
-static const luaL_reg task_meta[] = {
+static const luaL_Reg task_meta[] = {
{"__gc", l_task_gc}, /* will be called only for userdata */
{"__tostring", l_task_tostring},
{NULL, NULL}
void sglua_register_task_functions(lua_State* L)
{
/* create a table simgrid.task and fill it with task functions */
- luaL_openlib(L, TASK_MODULE_NAME, task_functions, 0);
+ 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 */
/* create the metatable for tasks, add it to the Lua registry */
luaL_newmetatable(L, TASK_MODULE_NAME);
/* simgrid.task mt */
/* fill the metatable */
- luaL_openlib(L, NULL, task_meta, 0);
+ 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 */
sglua_stack_dump("my_checkudata: ", L);
if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2))
- luaL_typerror(L, ud, tname);
+ XBT_ERROR("Error: Userdata is NULL, couldn't find metatable or top of stack does not equal element below it.");
lua_pop(L, 2);
return p;
}
static void sglua_register_core_functions(lua_State *L)
{
/* register the core C functions to lua */
- luaL_register(L, "simgrid", simgrid_functions);
+ /*luaL_Register(L, "simgrid", simgrid_functions);*/
+ lua_newtable(L);
+ luaL_setfuncs(L, simgrid_functions, 0);
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, "simgrid");
+
/* simgrid */
/* set a finalizer that cleans simgrid, by adding to the simgrid module a