+
+/**
+ * @brief Returns whether a Lua state is the maestro state.
+ * @param L a Lua state
+ * @return true if this is maestro
+ */
+int sglua_is_maestro(lua_State* L) {
+ return L == lua_maestro_state;
+}
+
+/**
+ * @brief Returns the maestro state.
+ * @return true the maestro Lua state
+ */
+lua_State* sglua_get_maestro(void) {
+ return lua_maestro_state;
+}
+
+/**
+ * Makes the appropriate Simgrid functions available to the Lua world.
+ * @param L a Lua world
+ */
+void register_c_functions(lua_State *L) {
+
+ /* register the core C functions to lua */
+ luaL_register(L, "simgrid", simgrid_funcs);
+
+ /* register the task methods to lua */
+ luaL_openlib(L, TASK_MODULE_NAME, Task_methods, 0); // create methods table, add it to the globals
+ luaL_newmetatable(L, TASK_MODULE_NAME); // create metatable for Task, add it to the Lua registry
+ luaL_openlib(L, 0, Task_meta, 0); // fill metatable
+ lua_pushliteral(L, "__index");
+ lua_pushvalue(L, -3); // dup methods table
+ lua_rawset(L, -3); // matatable.__index = methods
+ lua_pushliteral(L, "__metatable");
+ lua_pushvalue(L, -3); // dup methods table
+ lua_rawset(L, -3); // hide metatable:metatable.__metatable = methods
+ lua_pop(L, 1); // drop metatable
+
+ /* register the hosts methods to lua */
+ luaL_openlib(L, HOST_MODULE_NAME, Host_methods, 0);
+ luaL_newmetatable(L, HOST_MODULE_NAME);
+ luaL_openlib(L, 0, Host_meta, 0);
+ lua_pushliteral(L, "__index");
+ lua_pushvalue(L, -3);
+ lua_rawset(L, -3);
+ lua_pushliteral(L, "__metatable");
+ lua_pushvalue(L, -3);
+ lua_rawset(L, -3);
+ lua_pop(L, 1);
+
+ /* register the links methods to lua */
+ luaL_openlib(L, AS_MODULE_NAME, AS_methods, 0);
+ luaL_newmetatable(L, AS_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);
+}