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
lubocheng opened this Issue Oct 19, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@lubocheng

lubocheng commented Oct 19, 2017

这个怎么配置呢..

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Oct 19, 2017

Member

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

Member

waruqi commented Oct 19, 2017

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

@lubocheng

This comment has been minimized.

Show comment
Hide comment
@lubocheng

lubocheng Oct 19, 2017

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

lubocheng commented Oct 19, 2017

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

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Oct 19, 2017

Member

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

target("xxx")
    on_run(function (target)
        os.cd(path.directory(target:targetfile()))
        os.exec(target:targetfile())
    end)
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

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Oct 20, 2017

Member

我在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)
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