Skip to content

Custom Module

We can use import() to import custom modules (Lua scripts) to share logic across projects.

Basic Example

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)

Build and Run

bash
$ xmake
$ xmake run