#define LINK_MODULE_NAME "simgrid.Link"
#define ROUTE_MODULE_NAME "simgrid.Route"
#define AS_MODULE_NAME "simgrid.AS"
+#define TRACE_MODULE_NAME "simgrid.Trace"
/* ********************************************************************************* */
/* helper functions */
}
+static int Host_self(lua_State * L)
+{
+ m_host_t host = MSG_host_self();
+ lua_newtable(L);
+ m_host_t *lua_host =(m_host_t *)lua_newuserdata(L,sizeof(m_host_t));
+ *lua_host = host;
+ luaL_getmetatable(L, HOST_MODULE_NAME);
+ lua_setmetatable(L, -2);
+ lua_setfield(L, -2, "__simgrid_host");
+ return 1;
+
+}
+
+static int Host_get_property_value(lua_State * L)
+{
+ m_host_t ht = checkHost(L, -2);
+ const char *prop = luaL_checkstring(L, -1);
+ lua_pushstring(L,MSG_host_get_property_value(ht,prop));
+ return 1;
+}
/* ********************************************************************************* */
/* lua_stub_generator functions */
generate_sim(project_name);
generate_rl(project_name);
generate_makefile_local(project_name);
-
return 0;
}
-//***********Register Methods *******************************************//
+/***********************************
+ * Tracing
+ **********************************/
+static int trace_start(lua_State *L)
+{
+ TRACE_start();
+ return 1;
+}
+
+static int trace_category(lua_State * L)
+{
+ TRACE_category(luaL_checkstring(L, 1));
+ return 1;
+}
+static int trace_set_task_category(lua_State *L)
+{
+ TRACE_msg_set_task_category(checkTask(L, -2), luaL_checkstring(L, -1));
+ return 1;
+}
+
+static int trace_end(lua_State *L)
+{
+ TRACE_end();
+ return 1;
+}
+//***********Register Methods *******************************************//
/*
* Host Methods
*/
{"name", Host_get_name},
{"number", Host_number},
{"at", Host_at},
+ {"self",Host_self},
+ {"getPropValue",Host_get_property_value},
// Bypass XML Methods
{"new", console_add_host},
{"setFunction", console_set_function},
{0, 0}
};
+/**
+ * Tracing Functions
+ */
+static const luaL_reg Trace_methods[] = {
+ {"start",trace_start},
+ {"category",trace_category},
+ {"setTaskCategory",trace_set_task_category},
+ {"finish",trace_end},
+ {0,0}
+};
/*
* Environment related
*/
/* module management functions */
/* ********************************************************************************* */
-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)
{
- //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? */
/*register the routes methods to lua */
luaL_openlib(L, ROUTE_MODULE_NAME, Route_methods, 0);
- luaL_newmetatable(L, LINK_MODULE_NAME);
+ luaL_newmetatable(L, ROUTE_MODULE_NAME);
+ lua_pop(L, 1);
+
+ /*register the Tracing functions to lua */
+ luaL_openlib(L, TRACE_MODULE_NAME, Trace_methods, 0);
+ luaL_newmetatable(L, TRACE_MODULE_NAME);
lua_pop(L, 1);
/* Keep the context mechanism informed of our lua world today */