<bdo id='EvoRp'></bdo><ul id='EvoRp'></ul>
<tfoot id='EvoRp'></tfoot>
    <legend id='EvoRp'><style id='EvoRp'><dir id='EvoRp'><q id='EvoRp'></q></dir></style></legend>
    <i id='EvoRp'><tr id='EvoRp'><dt id='EvoRp'><q id='EvoRp'><span id='EvoRp'><b id='EvoRp'><form id='EvoRp'><ins id='EvoRp'></ins><ul id='EvoRp'></ul><sub id='EvoRp'></sub></form><legend id='EvoRp'></legend><bdo id='EvoRp'><pre id='EvoRp'><center id='EvoRp'></center></pre></bdo></b><th id='EvoRp'></th></span></q></dt></tr></i><div id='EvoRp'><tfoot id='EvoRp'></tfoot><dl id='EvoRp'><fieldset id='EvoRp'></fieldset></dl></div>
  1. <small id='EvoRp'></small><noframes id='EvoRp'>

    1. 从 C++/C 设置全局 LUA_PATH 变量?

      时间:2023-09-27

      <tfoot id='5COvs'></tfoot>

      <small id='5COvs'></small><noframes id='5COvs'>

        <i id='5COvs'><tr id='5COvs'><dt id='5COvs'><q id='5COvs'><span id='5COvs'><b id='5COvs'><form id='5COvs'><ins id='5COvs'></ins><ul id='5COvs'></ul><sub id='5COvs'></sub></form><legend id='5COvs'></legend><bdo id='5COvs'><pre id='5COvs'><center id='5COvs'></center></pre></bdo></b><th id='5COvs'></th></span></q></dt></tr></i><div id='5COvs'><tfoot id='5COvs'></tfoot><dl id='5COvs'><fieldset id='5COvs'></fieldset></dl></div>
      • <legend id='5COvs'><style id='5COvs'><dir id='5COvs'><q id='5COvs'></q></dir></style></legend>

              <tbody id='5COvs'></tbody>
              <bdo id='5COvs'></bdo><ul id='5COvs'></ul>

                本文介绍了从 C++/C 设置全局 LUA_PATH 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我试图直接从 C/C++ 设置我的全局 LUA_PATH 变量,我在我的 iPhone 应用程序中使用 Lua,所以我的路径往往会在应用程序之间发生变化(每个 iPhone 应用程序在设备中都有一个单独的文件夹).

                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 iPhone app has a separate folder in the device ).

                我知道我可以通过使用固定"路径重新编译 lua 来设置 LUA_PATH,但这远非理想.

                I know I could set the LUA_PATH by recompiling lua with a "fixed" path, but that's quite far from ideal.

                (我试图这样做是为了能够从我的 .lua 脚本中使用 require.

                ( I'm trying to do this in order to be able to use require, from my .lua scripts.

                有人可以帮我吗?

                推荐答案

                在 C++ 中:

                int setLuaPath( lua_State* L, const char* path )
                {
                    lua_getglobal( L, "package" );
                    lua_getfield( L, -1, "path" ); // get field "path" from table at top of stack (-1)
                    std::string cur_path = lua_tostring( L, -1 ); // grab path string from top of stack
                    cur_path.append( ";" ); // do your path magic here
                    cur_path.append( path );
                    lua_pop( L, 1 ); // get rid of the string on the stack we just pushed on line 5
                    lua_pushstring( L, cur_path.c_str() ); // push the new one
                    lua_setfield( L, -2, "path" ); // set the field "path" in table at -2 with value at top of stack
                    lua_pop( L, 1 ); // get rid of package table from top of stack
                    return 0; // all done!
                }
                

                我还没有测试或编译过它.我用过:http://lua.org/pil 和 http://lua.org/manual/5.1

                I haven't tested or compiled it. I used: http://lua.org/pil and http://lua.org/manual/5.1

                这篇关于从 C++/C 设置全局 LUA_PATH 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 Lua 和 C++ 管理堆栈 下一篇:使用句柄从 .lua 调用 lua 函数?

                相关文章

                  <bdo id='C6atb'></bdo><ul id='C6atb'></ul>

                  1. <small id='C6atb'></small><noframes id='C6atb'>

                  2. <legend id='C6atb'><style id='C6atb'><dir id='C6atb'><q id='C6atb'></q></dir></style></legend>
                  3. <tfoot id='C6atb'></tfoot>
                    <i id='C6atb'><tr id='C6atb'><dt id='C6atb'><q id='C6atb'><span id='C6atb'><b id='C6atb'><form id='C6atb'><ins id='C6atb'></ins><ul id='C6atb'></ul><sub id='C6atb'></sub></form><legend id='C6atb'></legend><bdo id='C6atb'><pre id='C6atb'><center id='C6atb'></center></pre></bdo></b><th id='C6atb'></th></span></q></dt></tr></i><div id='C6atb'><tfoot id='C6atb'></tfoot><dl id='C6atb'><fieldset id='C6atb'></fieldset></dl></div>