Setting the global LUA_PATH variable from C++/C?

前端 未结 7 549
说谎
说谎 2020-12-28 09:58

I\'m trying to set my global LUA_PATH variable directly from C/C++, I\'m using Lua from my iPhone applications, so my path tends does change between applications ( each iPho

7条回答
  •  没有蜡笔的小新
    2020-12-28 10:21

    You can set the LUA_PATH and LUA_CPATH within c++ very easily by executing a couple lual_dostring functions.

    luaL_dostring(L, "package.path = package.path .. ';?.lua'");
    luaL_dostring(L, "package.cpath = package.cpath .. ';?.dll'");
    

    These two line called after you have your lua_State (L here) and before your lual_loadfile() and lau_pcall() function calls will add to the currently set path and cpath. In this case I add to both an instruction to look local to the execution.

    It took me hours to find this solution.. I hope it helps.

提交回复
热议问题