Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5228a4e
chore: update .gitignore for macOS and Xcode
alex4814 Jan 23, 2025
bec1e0b
build(macnojit): remove deprecated VALID_ARCHS since Xcode 12
alex4814 Jan 23, 2025
5e94ace
feat: update cjson to 2.1.devel and make it submodule
alex4814 Jan 23, 2025
ba47392
build(macnojit): use of `-f` option in `cp` is strongly discouraged a…
alex4814 Jan 23, 2025
173e492
feat: update luajit to latest 2.1 rolling release and make it submodule
alex4814 Jan 24, 2025
2e0fe01
feat: remove deprecated `lua_getref` and fix compiler errors for late…
alex4814 Jan 24, 2025
a63b127
feat: replace cjson to openresty to get latest improvements
alex4814 Jan 24, 2025
2442c2e
build(macjit): build script for tolua on macOS using LuaJIT
alex4814 Jan 24, 2025
8c3a58e
build(Xcode): remove prefix.pch that includes `cocoa.h` which is not
alex4814 Jan 26, 2025
b8563b7
build(osxjit): fix shell script error
alex4814 Jan 26, 2025
fb15ea0
chore: update xcode project settings according to advices from Xcode …
alex4814 Jan 26, 2025
4aa8d99
feat: update luasocket from v3.0-rc1 to v3.1.0 release and make it su…
alex4814 Jan 26, 2025
928665e
build(Xcode): update source files of luasocket v3.1.0 in Xcode projects
alex4814 Jan 26, 2025
f1755f7
docs: update README.md
alex4814 Jan 26, 2025
1f60efd
feat: `bit` module is a LuaJIT built-in
alex4814 Jan 27, 2025
74ed831
build(ios): build script and Xcode project modifications for tolua li…
alex4814 Jan 29, 2025
0da0a4c
build(ios): update Xcode project settings according to advices from X…
alex4814 Jan 29, 2025
8b2b249
feat: update `struct` lib from v1.4 to v1.8
alex4814 Jan 30, 2025
8cecd44
feat: update `lpeg` source from v0.10 to v1.1.0 and make it submodule
alex4814 Jan 30, 2025
5faf579
build(Xcode): update Xcode project with latest `lpeg`
alex4814 Jan 30, 2025
c62b9b4
docs: update README.md
alex4814 Jan 30, 2025
00bbafe
build(win32): convert to CMake build system
alex4814 Feb 6, 2025
0912641
chore: update .gitignore to add CMake
alex4814 Feb 6, 2025
034d0fe
build(win32): improved build script and fix Release build
alex4814 Feb 7, 2025
feb1783
build: moved `copy` from script to cmake command
alex4814 Feb 7, 2025
90e98b5
build(android): cross-compile for Android arm64-v8a on Windows
alex4814 Feb 7, 2025
25b69a2
build(android): cross-compile for Android arm64-v8a on macOS and Linux
alex4814 Feb 7, 2025
8ba3781
build: fix Android and Windows build script
alex4814 Feb 7, 2025
5dd681c
build(osx): using leetal's iOS toolchain to build macOS universal binary
alex4814 Feb 8, 2025
d41e2a9
build(osx): fix missing debug option for LuaJIT
alex4814 Feb 8, 2025
8908111
build(ios): script to build tolua for iOS and improved for macOS
alex4814 Feb 8, 2025
e55ff18
build(ios): fix the inconsistent environment variables when compiling…
alex4814 Feb 8, 2025
a278516
build(win32): add copy tolua step for all scripts on win32
alex4814 Feb 9, 2025
1afc998
build(install): newer Unity could place Plugins in any folder
alex4814 Feb 10, 2025
8f12c4e
build: improved by writing vs path to a temp file
alex4814 Feb 10, 2025
c983315
fix: luajit static library should be linked as a whole archive
alex4814 Feb 10, 2025
be63f06
build(win32): add MinGW support
alex4814 Feb 11, 2025
adb7cda
build: improved LuaJIT static library filenames
alex4814 Feb 11, 2025
112bf55
build(mingw): symbols from LuaJIT needs to be exported by "-Wl,--expo…
alex4814 Feb 11, 2025
892fb8c
build(android): support MinGW as well and use LuaJIT static library
alex4814 Feb 11, 2025
653decf
docs: update READMD.md
alex4814 Feb 11, 2025
583e412
docs: update summary for build supported
alex4814 Feb 11, 2025
3850378
build: improve and fix MinGW for Android
alex4814 Feb 11, 2025
a60ffe8
build: refined build script for iOS and macOS
alex4814 Feb 12, 2025
1d3aa40
chore: ignore build and binary directories
alex4814 Feb 12, 2025
a9b77e7
chore: change LuaJIT submodule to a forked repo
alex4814 Feb 12, 2025
92b90c2
feat: support LuaJIT compile options
alex4814 Feb 12, 2025
8725f7c
fix(build): expansion of XCFLAGS
alex4814 Feb 13, 2025
87219dc
fix: use `libtool` to merge tolua and libluajit
alex4814 Feb 13, 2025
6f9aa67
build(msvc): refactor and fix argument parsing
alex4814 Feb 16, 2025
87a02cf
build(msvc): add support for nogc64 compile option
alex4814 Feb 16, 2025
2f80470
build(msvc): add support for windows arm64
alex4814 Feb 16, 2025
cdfea78
build: use make instead of mingw32-make
alex4814 Feb 18, 2025
1691794
build: fix cross build for Android on Windows using gcc
alex4814 Feb 19, 2025
6078a18
build(android): support `armeabi-v7a`
alex4814 Feb 20, 2025
71eec6d
build(osx): support x86_64 and arm64
alex4814 Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
81 changes: 81 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# Created by https://www.toptal.com/developers/gitignore/api/c,cmake,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=c,cmake,macos

### C ###
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch
Expand All @@ -30,3 +42,72 @@

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

### CMake ###
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

### CMake Patch ###
CMakeUserPresets.json

# External projects
*-prefix/

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

# End of https://www.toptal.com/developers/gitignore/api/c,cmake,macos

Build/
Plugins/
13 changes: 13 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[submodule "luajit-2.1"]
path = luajit-2.1
url = git@github.com:alex4814/LuaJIT.git
[submodule "cjson"]
path = cjson
url = git@github.com:openresty/lua-cjson.git
[submodule "luasocket"]
path = luasocket
url = git@github.com:lunarmodules/luasocket.git
[submodule "lpeg"]
path = lpeg
url = git@github.com:alex4814/lpeg-luajit.git
branch = luajit-v2.1
129 changes: 129 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
cmake_minimum_required(VERSION 3.24)

cmake_policy(SET CMP0091 NEW)

project(tolua LANGUAGES C)

# Options
option(LJ_GC64 "LuaJIT: Use 64 bit GC objects" ON)
option(LJ_ENABLE_LUA52COMPAT "LuaJIT: Enable Lua 5.2 compatibility" OFF)

# Sources
set(TOLUA_SRC
tolua.c
int64.c
uint64.c
)
source_group(tolua FILES ${TOLUA_SRC})

set(LPEG_SRC
lpeg/lpcap.c
lpeg/lpcode.c
lpeg/lpcset.c
lpeg/lpprint.c
lpeg/lptree.c
lpeg/lpvm.c
)
source_group(liblpeg FILES ${LPEG_SRC})

set(STRUCT_SRC
struct.c
)
source_group(libstruct FILES ${STRUCT_SRC})

set(CJSON_SRC
cjson/strbuf.c
cjson/lua_cjson.c
cjson/fpconv.c
)
source_group(libcjson FILES ${CJSON_SRC})

set(PROTOBUF_SRC
pb.c
)
source_group(libprotobuf FILES ${PROTOBUF_SRC})

set(LUASOCKET_SRC
luasocket/src/auxiliar.c
luasocket/src/buffer.c
luasocket/src/compat.c
luasocket/src/except.c
luasocket/src/inet.c
luasocket/src/io.c
luasocket/src/luasocket.c
luasocket/src/options.c
luasocket/src/select.c
luasocket/src/tcp.c
luasocket/src/timeout.c
luasocket/src/udp.c
)
if (WIN32 AND NOT CYGWIN)
list(APPEND LUASOCKET_SRC luasocket/src/wsocket.c)
else()
list(APPEND LUASOCKET_SRC luasocket/src/usocket.c)
endif()
source_group(libluasocket FILES ${LUASOCKET_SRC})

set(LIB_SRC
${LPEG_SRC}
${STRUCT_SRC}
${CJSON_SRC}
${LUASOCKET_SRC}
)
set_property(SOURCE ${LIB_SRC} PROPERTY COMPILE_DEFINITIONS LUA_LIB)

# toLua Library
if (WIN32 AND NOT CYGWIN)
add_library(tolua SHARED
${TOLUA_SRC}
${LIB_SRC}
)
target_link_libraries(tolua PRIVATE ws2_32)
elseif (IOS)
add_library(tolua STATIC
${TOLUA_SRC}
${LIB_SRC}
)
target_link_options(tolua PRIVATE -ObjC)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_library(tolua MODULE
${TOLUA_SRC}
${LIB_SRC}
)
set_property(TARGET tolua PROPERTY BUNDLE TRUE)
else ()
add_library(tolua SHARED
${TOLUA_SRC}
${LIB_SRC}
)
endif ()
set_property(TARGET tolua PROPERTY C_STANDARD 99)

# Depends on LuaJIT
include(${CMAKE_SOURCE_DIR}/cmake/luajit2.cmake)

add_library(luajit2 STATIC IMPORTED)
set_target_properties(luajit2 PROPERTIES
IMPORTED_LOCATION ${LUAJIT_LIB_PATH}
)
add_dependencies(luajit2 luajit2_build)

# Target options
if (MSVC)
set_property(TARGET tolua PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()
if (WIN32 AND NOT CYGWIN)
target_compile_definitions(tolua PRIVATE LUA_BUILD_AS_DLL)
endif ()

# Link LuaJIT
target_include_directories(tolua PRIVATE ${LUAJIT_SOURCE_ROOT})
target_link_libraries(tolua PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,luajit2>")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_link_options(tolua PRIVATE -Wl,--export-all-symbols)
endif ()
if (IOS)
add_custom_command(TARGET tolua POST_BUILD
COMMAND /usr/bin/libtool -static -o $<TARGET_FILE:tolua> $<TARGET_FILE:tolua> $<TARGET_FILE:luajit2>
)
endif ()
157 changes: 132 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,132 @@
# tolua_runtime
**Build**<br>
pc: build_win32.sh build_win64.h (mingw + luajit2.0.4) <br>
android: build_arm.sh build_x86.sh (mingw + luajit2.0.4) <br>
mac: build_osx.sh (xcode + luac5.1.5 for luajit can't run on unity5) <br>
ios: build_ios.sh (xcode + luajit2.1 beta) <br>

NDK 版本:android-ndk-r10e 默认安装到 D:/android-ndk-r10e<br>
https://dl.google.com/android/repository/android-ndk-r10e-windows-x86_64.zip<br>
Msys2配置说明<br>
https://github.com/topameng/tolua_runtime/wiki<br>
配置好的Msys2下载<br>
https://pan.baidu.com/s/1c2JzvDQ<br>

# Libs
**cjson**<br>
https://github.com/mpx/lua-cjson<br>
**protoc-gen-lua**<br>
https://github.com/topameng/protoc-gen-lua<br>
**LuaSocket** <br>
https://github.com/diegonehab/luasocket<br>
**struct**<br>
http://www.inf.puc-rio.br/~roberto/struct/<br>
**lpeg**<br>
http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html
ToLua Runtime
=============
Maintained ToLua runtime for Unity games using ToLua.


Motivation
----------
- Mainly to update outdated libraries.
- Upgrade build script or toolchains for each platforms.


Build
-----
CMake 3.14+ is required to build `tolua` and cross-compiling.

| | Windows (MSYS2) | Windows | macOS | Linux |
| ----------------- | ------------------ | ------------------------- | ------------------ | ------------------ |
| Windows (x86) | :heavy_check_mark: | :heavy_check_mark: (msvc) | :x: | :x: |
| Windows (x64) | :heavy_check_mark: | :heavy_check_mark: (msvc) | :x: | :x: |
| Windows (arm64) | :x: | :heavy_check_mark: (msvc) | :x: | :x: |
| Android (arm) | :heavy_check_mark: | :x: | :x: | :x: |
| Android (arm64) | :heavy_check_mark: | :heavy_check_mark: (gcc) | :heavy_check_mark: | :heavy_check_mark: |
| macOS (universal) | :x: | :x: | :heavy_check_mark: | :x: |
| macOS (arm64) | :x: | :x: | :heavy_check_mark: | :x: |
| macOS (x64) | :x: | :x: | :heavy_check_mark: | :x: |
| iOS (arm64) | :x: | :x: | :heavy_check_mark: | :x: |

> NOTE: Every predefiend build script would install the target library to *Plugins*
> folder, which could be placed on any subfolder in *Assets*, according to the
> [disccusion](https://discussions.unity.com/t/plugins-folder-inside-a-unity-package-does-it-have-to-be-on-the-root-folder-or-not/934638/2)
> for newer version of Unity.

### Windows
When targeting Windows, MINGW is preferred over MSVC (luajit options not supported).

#### MSVC (WIP)
Visual Studio 2017+ should work (Tested for Visual Studio 2022)

```bat
> .\build_tolua_windows_x86.bat
> .\build_tolua_windows_x64.bat
> .\build_tolua_windows_arm64.bat
```

> IMPORTANT: Symbols from LuaJIT is stuck for exporting to shared library now.
> Refer to [#1341](https://github.com/LuaJIT/LuaJIT/issues/1341) for any progress.

#### MSYS2
Install MSYS2 and prepare MSYS2 environment and toolchains.

```bash
$ pacman -S git
$ pacman -S make
$ # For x86
$ pacman -S mingw-w64-i686-cmake
$ pacman -S mingw-w64-i686-gcc
$ # For x86_64
$ pacman -S mingw-w64-x86_64-cmake
$ pacman -S mingw-w64-x86_64-gcc
```

To build, symply run:
```bash
$ ./build_tolua_windows_mingw.sh
```

### Android
To build for Android, you need to install the Android NDK and Ninja.

The default ANDROID_NATIVE_API_LEVEL is set to 21.


Set environment variable `ANDROID_NDK_HOME` to the path of the NDK,
e.g. `export ANDROID_NDK_HOME=/path/to/android-ndk-r27c` on UNIX-like systems, or
pass `-DANDROID_NDK=/path/to/android-ndk-r27c` to CMake command.

#### Cross-compiling on Windows
Using [Scoop](https://scoop.sh/) or other package managers to install `gcc`.
```bat
> set ANDROID_NDK_HOME=C:\path\to\android-ndk-r27c && .\build_tolua_android_arm64.bat
```

For MinGW, it is the same as build on UNIX-like system.
```bash
$ ANDROID_NDK_HOME=C:/path/to/android-ndk-r27c ./build_tolua_android_arm64.sh
$ ANDROID_NDK_HOME=C:/path/to/android-ndk-r27c ./build_tolua_android_arm.sh
```

#### Cross-compiling on UNIX-like
```bash
$ ANDROID_NDK_HOME=/path/to/android-ndk-r27c ./build_tolua_android_arm64.sh
$ ANDROID_NDK_HOME=/path/to/android-ndk-r27c ./build_tolua_android_arm.sh
```

### macOS
Xcode is needed for macOS.
The default DEPLOYMENT_TARGET is set to 11.0.

```bash
$ ./build_tolua_osx_universal.sh
$ ./build_tolua_osx_arm64.sh
$ ./build_tolua_osx_x64.sh
```

### iOS
Xcode is needed to build for iOS.
The default DEPLOYMENT_TARGET is set to 13.0.

```bash
$ ./build_tolua_ios_arm64.sh
```


Libraries
---------
LuaJIT is updated to (current) latest v2.1 branch (commit at 2025-01-13 16:22:22),
but currently using a [forked repository](https://github.com/alex4814/luajit).

| | Version | Notes |
| ---------------------------- | --------- | ----------------------------- |
| [openresty/lua-cjson][1] | v2.1.0.14 | Moved from [mpx/lua-cjson][2] |
| [lunarmodules/luasocket][3] | v3.1.0 | original v3.0-rc1 |
| [topameng/protoc-gen-lua][4] | | |
| [struct][5] | v1.8 | original v1.4 |
| [alex4814/lpeg-luajit][6] | v1.1.0 | original v0.10 |

[1]: https://github.com/openresty/lua-cjson/tree/2.1.0.14
[2]: https://github.com/mpx/lua-cjson
[3]: https://github.com/lunarmodules/luasocket/tree/v3.1.0
[4]: https://github.com/topameng/protoc-gen-lua
[5]: http://www.inf.puc-rio.br/~roberto/struct/
[6]: https://github.com/alex4814/lpeg-luajit
Loading