Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用Lua“;要求;使用physfs从拉链内部_C++_C_Lua_Physfs - Fatal编程技术网

C++ 使用Lua“;要求;使用physfs从拉链内部

C++ 使用Lua“;要求;使用physfs从拉链内部,c++,c,lua,physfs,C++,C,Lua,Physfs,在使用physfs时,通过使用luaL_dostring并在我自己身上读取文件,加载和运行lua脚本非常容易,但在使用“require”时,显然会遇到麻烦 有人处理过这个问题吗?我需要。。。。重写lua的一部分?我真的不想那样做 谢谢 更新,这就是我让它工作的方式 static int MyLoader(lua_State *L) { const char *name = luaL_checkstring(L, 1); std::string s = name; std:

在使用physfs时,通过使用luaL_dostring并在我自己身上读取文件,加载和运行lua脚本非常容易,但在使用“require”时,显然会遇到麻烦

有人处理过这个问题吗?我需要。。。。重写lua的一部分?我真的不想那样做

谢谢

更新,这就是我让它工作的方式

static int MyLoader(lua_State *L)
{
    const char *name = luaL_checkstring(L, 1);
    std::string s = name;
    std::replace( s.begin(), s.end(), '.', '/'); // replace all '.' to '/'
    s += ".lua"; // apend .lua
    File moduleFile = FileManager::ReadFile(s.c_str());
    if( luaL_loadbuffer(L, moduleFile.data, moduleFile.fileLength, name) ) {
        lua_pop(L, 1);
    }
    return 1;
}
然后在创建lua状态之后

lua_register(L, "my_loader", MyLoader);
const char* str = "table.insert(package.searchers, 2, my_loader) \n";
luaL_dostring(L, str);
包含
require
的加载程序函数列表

如果希望
require
从zip文件加载文件,则需要添加一个检查zip文件的函数。如果zipfile中存在路径,则将其提取到内存缓冲区,并调用
luaL\u loadbuffer
checkload
,就像
searcher\u Lua
那样