8 #include "msg/datatypes.h"
9 #include "xbt/sysdep.h"
11 #include "xbt/asserts.h"
15 // *** Testing Stuff !!
17 XBT_LOG_NEW_DEFAULT_CATEGORY(lua,"Lua bindings");
20 //***************************** LOAD LUA *************************************************
21 static int load_lua(char * luaFile, lua_State *L) {
25 if (luaL_loadfile(L, luaFile) || lua_pcall(L, 0, 0, 0)) {
26 printf("error while parsing %s: %s", luaFile, lua_tostring(L, -1));
34 int lua_wrapper(int argc, char *argv[]) {
35 lua_State *L = lua_open();
36 load_lua(lua_file, L);
38 // Seek the right lua function
39 lua_getglobal(L,argv[0]);
40 if(!lua_isfunction(L,-1)) {
42 ERROR1("The lua function %s does not seem to exist",argv[0]);
46 // push arguments onto the stack
49 lua_pushstring(L,argv[i]);
52 lua_call(L,argc-1,0); // takes argc-1 argument, returns nothing
54 // User process terminated
62 //*****************************************************************************
64 extern const char*xbt_ctx_factory_to_use; /*Hack: let msg load directly the right factory */
66 int main(int argc,char * argv[]) {
67 MSG_error_t res = MSG_OK;
70 xbt_ctx_factory_to_use = "lua";
71 MSG_global_init(&argc, argv);
75 printf("Usage: %s platform_file deployment_file lua_script\n", argv[0]);
76 printf("example: %s msg_platform.xml msg_deployment.xml script_lua.lua\n", argv[0]);
81 /* MSG_config("surf_workstation_model","KCCFLN05"); */
82 SIMIX_ctx_lua_factory_loadfile(argv[3]);
84 MSG_create_environment(argv[1]);
85 MSG_launch_application(argv[2]);
90 INFO1("Simulation time %g", MSG_get_clock());