跳转到内容

自定义模块

我们可以使用 import() 导入自定义模块(Lua 脚本),以便在项目中共享逻辑。

基础示例

EXPLORER
src
main.cpp
xmake
modules
foo.lua
hello.lua
xmake.lua
Lua xmake.lua
12345678910
add_rules("mode.debug", "mode.release")

add_moduledirs("xmake")

target("test")
    set_kind("binary")
    add_files("src/main.cpp")
    on_load(function (target)
        import("modules.hello").say("xmake")
    end)

编译运行

bash
$ xmake
$ xmake run