Qt与Lua | lua文件的放置位置 [英] Qt with Lua | Where to place lua file(s)

查看:141
本文介绍了Qt与Lua | lua文件的放置位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个cpp文件,其中的main方法实现了对lua的调用. 编译+执行qt项目时,出现以下错误:

I've created a cpp file with the main method implementing calls to lua. When compiling + executing the qt project I receive the following error:

PANIC:调用Lua API时出现不受保护的错误(试图调用字符串值)

PANIC: unprotected error in call to Lua API (attempt to call a string value)

问题是lua找不到要执行的lua文件(至少我认为是).因此,我将文件复制到了所有调试目录和主目录,但仍然无法正常工作.

The problem is that lua cannot find the lua file to be executed (at least I think it is). So I copied the file to all the debug dirs and the main dir but it still didn't work.

感谢您的帮助!

main.cpp

#include <stdio.h>

extern "C" {
    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"
}

lua_State* L;

int main(int argc, char *argv[])
{


    /* initialize Lua */
    L = luaL_newstate();

    /* load Lua base libraries */
    luaL_openlibs(L);

    /* load the script */
    luaL_loadfile(L, "test.lua");

    lua_call(L, 0, 0);

    /* cleanup Lua */
    lua_close(L);

}

和文件test.lua

and the file test.lua

-- test

print("Hello World")

推荐答案

Qt似乎使用用户目录作为默认路径.

It seems like Qt uses the user's directory as default path.

您可以通过以下方式对此进行验证:(感谢丰富)

You can validate this with: (thanks Rich)

QDir dir(".");
qDebug() << dir.absolutePath();

将lua脚本放入此文件夹时,所有内容都像一个超级按钮.

When putting the lua script into this folder everything works like a charm.

可以使用以下命令设置工作目录:

The working directory can be set with the following command:

QDir::setCurrent()

并与

QCoreApplication::applicationFilePath() 

可以将路径设置为exe登录的位置.

The path can be set to where the exe resigns in.

这篇关于Qt与Lua | lua文件的放置位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆