|
37 L = luaL_newstate();38 luaL_openlibs(L); /* Load Lua libraries */39 setLuaPath(L, "/path/to/mydir/");40 status = luaL_loadfile(L, "my.lua");41 if (status) {42 printf("Couldn't load file: %s\n", lua_tostring(L, -1));43 exit(1);44 }
[1] http://pastebin.com/xPjx8Vpy48 int setLuaPath( lua_State* L, const char* path )49 {50 char *cur_path;51 size_t len;52 char* mypath;53 lua_getglobal( L, "package" );54 lua_getfield( L, -1, "path" );55 cur_path = lua_tostring( L, -1);56 mypath = malloc(strlen(cur_path) + strlen(path) + 9);57 strcpy(mypath,cur_path);58 strcat(mypath,";");59 strcat(mypath,path);60 strcat(mypath,"?.lua;");61 lua_pop( L, 1 );62 lua_pushstring( L, mypath) ;63 lua_setfield( L, -2, "path" );64 lua_pop( L, 1 );65 return 0;66 }