Skip to content

Commit

Permalink
[lua] Add cffi module
Browse files Browse the repository at this point in the history
  • Loading branch information
lampysprites committed May 1, 2024
1 parent 2942aba commit 70d3c90
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@
[submodule "third_party/tinyxml2"]
path = third_party/tinyxml2
url = https://github.com/aseprite/tinyxml2.git
[submodule "third_party/libffi"]
path = third_party/libffi
url = https://github.com/lampysprites/libffi.git
[submodule "third_party/cffi-lua"]
path = third_party/cffi-lua
url = https://github.com/lampysprites/cffi-lua.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ option(ENABLE_NEWS "Enable the news in Home tab" on)
option(ENABLE_UPDATER "Enable automatic check for updates" on)
option(ENABLE_SCRIPTING "Compile with scripting support" on)
option(ENABLE_WEBSOCKET "Compile with websocket support" on)
option(ENABLE_FFI "Compile with FFI scripting support" on)
option(ENABLE_TESTS "Compile unit tests" off)
option(ENABLE_BENCHMARKS "Compile benchmarks" off)
option(ENABLE_TRIAL_MODE "Compile the trial version" off)
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ if(ENABLE_WEBSOCKET)
add_definitions(-DENABLE_WEBSOCKET)
endif()

if(ENABLE_FFI)
add_definitions(-DENABLE_FFI)
endif()

######################################################################
# Aseprite Libraries (in preferred order to be built)

Expand Down
4 changes: 4 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,10 @@ if(ENABLE_SCRIPTING)
if(ENABLE_WEBSOCKET)
target_link_libraries(app-lib ixwebsocket)
endif()

if(ENABLE_FFI)
target_link_libraries(app-lib luacffi)
endif()
endif()

if(ENABLE_UPDATER)
Expand Down
12 changes: 12 additions & 0 deletions src/app/script/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include "ui/base.h"
#include "ui/cursor_type.h"
#include "ui/mouse_button.h"
#if ENABLE_FFI
#include <lua.hh>
#include <ffi.h>
#endif

#include <fstream>
#include <sstream>
Expand Down Expand Up @@ -519,6 +523,14 @@ Engine::Engine()
register_websocket_class(L);
#endif

// Register FFI module
#if ENABLE_FFI
ffi_module_open(L);
lua_pushvalue(L, -1);
lua_setglobal(L, "ffi");
lua_pop(L, 1);
#endif

// Check that we have a clean start (without dirty in the stack)
ASSERT(lua_gettop(L) == top);
}
Expand Down
16 changes: 16 additions & 0 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ if(ENABLE_SCRIPTING)
add_subdirectory(IXWebSocket)
target_include_directories(ixwebsocket PUBLIC)
endif()

if(ENABLE_FFI)
add_subdirectory(libffi)
# main.cc is not required
add_library(luacffi
cffi-lua/src/util.cc
cffi-lua/src/ffilib.cc
cffi-lua/src/parser.cc
cffi-lua/src/ast.cc
cffi-lua/src/lib.cc
cffi-lua/src/ffi.cc
)
target_compile_definitions(luacffi PUBLIC FFI_LITTLE_ENDIAN)
target_include_directories(luacffi PUBLIC cffi-lua/src libffi/include ${CMAKE_CURRENT_BINARY_DIR}/libffi/include/)
target_link_libraries(luacffi lua lualib lauxlib ffi_static)
endif()

endif()

Expand Down
1 change: 1 addition & 0 deletions third_party/cffi-lua
Submodule cffi-lua added at 65ead3
1 change: 1 addition & 0 deletions third_party/libffi
Submodule libffi added at 067041

0 comments on commit 70d3c90

Please sign in to comment.