-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Byte-compile and embed builtin Lua modules
FOr now this is only c_libs, but in future more builtin modules will be written in Lua.
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,5 @@ install(FILES | |
${CMAKE_CURRENT_BINARY_DIR}/lege_export.hpp | ||
DESTINATION include/lege | ||
) | ||
|
||
add_subdirectory(modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Lua modules: | ||
# These are byte-compiled and embedded in liblege, then preloaded by the library | ||
function(add_lua_module MODULE_NAME SOURCE_FILE) | ||
find_program(LUAJIT luajit) | ||
if(NOT LUAJIT) | ||
message(FATAL_ERROR "LuaJIT not found") | ||
endif() | ||
|
||
set(luajit_compile_opts "-b" "-t" "h") | ||
|
||
if(CMAKE_BUILD_TYPE MATCHES Debug) | ||
list(APPEND luajit_compile_opts "-g") | ||
else() | ||
list(APPEND luajit_compile_opts "-s") | ||
endif() | ||
|
||
set(OUTPUT_HEADER "lmod_${MODULE_NAME}.h") | ||
|
||
add_custom_command( | ||
OUTPUT ${OUTPUT_HEADER} | ||
COMMAND ${LUAJIT} | ||
ARGS ${luajit_compile_opts} "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_HEADER}" | ||
DEPENDS ${SOURCE_FILE} | ||
COMMENT "Byte-compiling Lua module to ${OUTPUT_HEADER}" | ||
) | ||
|
||
add_custom_target(lmod_${MODULE_NAME} DEPENDS ${OUTPUT_HEADER}) | ||
add_dependencies(lege lmod_${MODULE_NAME}) | ||
endfunction() | ||
|
||
foreach(module c_libs) | ||
add_lua_module(${module} ${module}.lua) | ||
endforeach() |