Skip to content

Commit

Permalink
Fix #4: Add example build script
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinkaa committed Sep 26, 2021
1 parent 6bf8e98 commit d6d3f18
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*_wrap.c
build/
.xmake/
20 changes: 19 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,27 @@

### Lua ###

> Example build:
```sh
# This example build script requires `xmake` and `swig` installed.
# `xmake.lua` in this repo is used to build the Lua `.so` module. Should work on Windows as well to build a `.dll`.
# You can use Lua 5.1~5.4 too, but you need to make changes in the `xmake.lua` accordingly.
xrepo install "luajit 2.1.0-beta3" && xmake build "swigraylib_lua"

This comment has been minimized.

Copy link
@waruqi

waruqi Sep 27, 2021

不需要xrepo,直接执行 xmake 就能自动装包

This comment has been minimized.

Copy link
@Rinkaa

Rinkaa Sep 28, 2021

Author Member

确实,感谢指出👍
其实我有意识到xmake能自动装包,但是当时犹豫了一下,因为打算把生成不同语言binding的target放在同一个xmake.lua里,用了在project scope里add_requires("luajit 2.1.0-beta3", {optional=true})设成可选包的办法,这样等加了py之类的其他binding以后编译就不会需要装luajit
也许更好的解决思路是每个语言的binding分别设一个project,就不用再把luajit设成可选包,换成让xmake自动装包

This comment has been minimized.

Copy link
@waruqi

waruqi Sep 28, 2021

定义 option 走 if is_config("lua") then add_requires("lua")

选择性装哪些

This comment has been minimized.

Copy link
@Rinkaa

Rinkaa Sep 28, 2021

Author Member

原来还可以这样,学到了

```

> Print raylib version in the terminal:
```sh
# Start luajit to test. You should change path of the output library accordingly.
luajit -i -e "package.cpath=package.cpath..';./build/linux/x86_64/release/libswig?_lua.so'"
> raylib = require "raylib"
> print(raylib.RAYLIB_VERSION)
3.7
```

> Basic window in Lua:
```lua
-- Original version in C: https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window.c, by Ramon Santamaria (@raysan5)
local raylib = require "raylib"

local screenWidth, screenHeight = 800, 450
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window")
raylib.SetTargetFPS(60)
Expand Down
38 changes: 38 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
add_rules("mode.release", "mode.debug")
set_languages("c99")
add_requires("raylib 3.7.0")

-- Choose one of the Lua versions:
-- add_requires("lua 5.3", {optional=true})
-- add_requires("lua 5.4, {optional=true}")
add_requires("luajit 2.1.0-beta3", {optional=true})

target("swigraylib_lua")
set_kind("shared")
before_build(function(target)
local raylibDefs = {"-D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33 -DPHYSAC_IMPLEMENTATION"}
if is_plat("windows") then
raylibDefs[#raylibDefs+1] = "-D_WIN32"
elseif is_plat("linux") then
raylibDefs[#raylibDefs+1] = "-D__linux__"
elseif is_plat("macosx") then
raylibDefs[#raylibDefs+1] = "-D__APPLE__"
else
os.raise("This xmake script doesn't support this target platform at the moment...")
end
local swigParams = {"-lua", "-no-old-metatable-bindings"}
for i = 1, #raylibDefs do swigParams[#swigParams+1] = raylibDefs[i] end
swigParams[#swigParams+1] = "raylib.i"
os.runv("swig", swigParams)
cprint("${yellow underline}SwigCmd: swig "..table.concat(swigParams, ' ').." ${clear}")
target:add("cxflags", raylibDefs)
end)
if is_plat("linux") then
add_cxflags("-fPIC")
end
add_packages("raylib")
add_files("raylib_wrap.c")

-- Choose one of the Lua package:
-- add_packages("lua")
add_packages("luajit")

1 comment on commit d6d3f18

@waruqi
Copy link

@waruqi waruqi commented on d6d3f18 Sep 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next version of xmake will support swig/lua. see xmake-io/xmake#1622 (comment)

Please sign in to comment.