我有个lua文件需要在qt中调用,
lua_State *lu = luaL_newstate();
int code = luaL_loadfile(lu, "parse.lua"); //文件读取不到
问题来了这个lua文件应该如何放到qt工程目录中?
以下是无效的:
试了把lua放到qrc资源中,但是":/.../.." 这种路径字符串无法被luaL_loadfile处理?
qt工程add other files 加入lua文件,(.pro配置中添加distfiles属性)
手动采用源码存储的相对路径
以下是有效的:
直接指定lua的绝对路径
QFile读取lua到字符串,用lua_loadbuffer
但是我想用lua_loadfile....
我理想的是qt在build可执行文件时候把lua脚本直接放在mac的app包里(如果是在mac上编译),或者win上直接写进exe的二进制里?这个思路是对的么,还是有其他方式?
阿神2017-04-17 13:49:52
When running in QtCreator, the running directory is the build directory, not the directory where the source code is located
qDebug() << QDir::currentPath();
So the lua script file should be in the build directory.
When using resources, the file content will be directly embedded into the program, read using QFile, and then lua_loadbuffer