Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <lua.h>
- #include <lauxlib.h>
- #include <lualib.h>
- int main(){
- int status = 0;
- lua_State *L;
- /*
- * All Lua contexts are held in this structure. We work with it almost
- * all the time.
- */
- L = luaL_newstate();
- luaL_openlibs(L); /* Load Lua libraries */
- /* Load the file containing the script we are going to run */
- setLuaPath(L, "/path/to/mydir/");
- status = luaL_loadfile(L, "my.lua");
- printf("%s:%d: Reached status %d\n",__func__, __LINE__,
- status);
- if (status) {
- /* If something went wrong, error message is at the top of */
- /* the stack */
- printf("Couldn't load file: %s\n", lua_tostring(L, -1));
- exit(1);
- }
- return ;
- } /* ----- end of function get_radio1_profilename ----- */
- int setLuaPath( lua_State* L, const char* path )
- {
- char *cur_path;
- size_t len;
- char* mypath;
- lua_getglobal( L, "package" );
- lua_getfield( L, -1, "path" ); // get field "path" from table at top of stack (-1)
- cur_path = lua_tostring( L, -1); // grab path string from top of stack
- mypath = malloc(strlen(cur_path) + strlen(path) + 9);
- strcpy(mypath,cur_path);
- strcat(mypath,";");
- strcat(mypath,path);
- strcat(mypath,"?.lua;");
- lua_pop( L, 1 ); // get rid of the string on the stack we just pushed on line 5
- lua_pushstring( L, mypath) ;
- lua_setfield( L, -2, "path" );
- lua_pop( L, 1 );
- return 0; // all done!
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement