Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c加载同目录lua脚本可正常执行,用xmake r 是错误的,说明xmake没有把程序运行的目录作为当前目录啊 #145

Closed
tianxiayu007 opened this issue Oct 19, 2017 · 4 comments

Comments

@tianxiayu007
Copy link

这个怎么配置呢..

@waruqi
Copy link
Member

waruqi commented Oct 19, 2017

?能否把执行的命令详细贴下 还有输出信息。。我看下?

@tianxiayu007
Copy link
Author

tianxiayu007 commented Oct 19, 2017

hello.exe会加载同目录下的lua文件,控制台单独执行可正常执行,用xmake r 不行,所以感觉路径错了,找不到lua文件
github传不上图,百度网盘也禁了..没法玩了..!

@waruqi
Copy link
Member

waruqi commented Oct 19, 2017

xmake r 默认是直接在工程根目录执行的 。这个的默认路径我可以改进下。当前你可以通过自定义on_run来修改当前执行目录

target("xxx")
    on_run(function (target)
        os.cd(path.directory(target:targetfile()))
        os.exec(target:targetfile())
    end)

@waruqi
Copy link
Member

waruqi commented Oct 20, 2017

我在master上修复这个问题了,你可以通过powershell更新下master版本试试,或者直接 覆盖安装目录下的 xmake/xmake/actions/run/main.lua 文件。

另外之前给的例子 也有点问题,应该是:

target("xxx")
    on_run(function (target)
        local targetfile = path.absolute(target:targetfile()) -- 切换目录前,先保存下target绝对路径, target:targetfile() 默认提供的是相对路径
        os.cd(path.directory(target:targetfile()))
        os.exec(targetfile)
    end)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants