Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions cmake/FindLuaJIT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#
# CMake Find LuaJIT library by Parra Studios
# CMake script to find LuaJIT library.
#
# Copyright (C) 2016 - 2026 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Find LuaJIT library and include paths
#
# LUAJIT_FOUND - True if LuaJIT library was found
# LUAJIT_INCLUDE_DIR - LuaJIT headers path
# LUAJIT_LIBRARY - List of LuaJIT libraries

# Prevent verbosity if already included
if(LUAJIT_FOUND)
set(LUAJIT_FIND_QUIETLY TRUE)
endif()

include(FindPackageHandleStandardArgs)

set(LUAJIT_SUFFIXES
x86_64-linux-gnu
aarch64-linux-gnu
arm-linux-gnueabi
arm-linux-gnueabihf
i386-linux-gnu
mips64el-linux-gnuabi64
mipsel-linux-gnu
powerpc64le-linux-gnu
s390x-linux-gnu
)

# LuaJIT library names vary by platform
set(LUAJIT_LIBRARY_NAMES
luajit-5.1
${CMAKE_SHARED_LIBRARY_PREFIX}luajit-5.1${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_STATIC_LIBRARY_PREFIX}luajit-5.1${CMAKE_STATIC_LIBRARY_SUFFIX}
)

find_library(LUAJIT_LIBRARY
NAMES ${LUAJIT_LIBRARY_NAMES}
PATHS /usr /usr/lib /usr/local /opt/luajit /opt/local
PATH_SUFFIXES lib lib64 ${LUAJIT_SUFFIXES}
)

find_path(LUAJIT_INCLUDE_DIR luajit.h
PATHS /usr /usr/include /usr/local /opt/luajit /opt/local
PATH_SUFFIXES luajit-2.0 luajit-2.1 ${LUAJIT_SUFFIXES}
)

# Define LuaJIT cmake module
find_package_handle_standard_args(LuaJIT DEFAULT_MSG LUAJIT_LIBRARY LUAJIT_INCLUDE_DIR)

# Mark cmake module as advanced
mark_as_advanced(LUAJIT_INCLUDE_DIR LUAJIT_LIBRARY)
15 changes: 6 additions & 9 deletions source/loaders/lua_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ endif()
# External dependencies
#

# TODO: Implement the find script (and probably the install script too)
# for LuaJIT2, meanwhile we will be using the find script for Lua of Kitware

# find_package(LuaJIT2 REQUIRED)

find_package(Lua REQUIRED)
find_package(LuaJIT REQUIRED)

#
# Plugin name and options
Expand Down Expand Up @@ -50,11 +45,13 @@ set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")

set(headers
${include_path}/lua_loader.h
${include_path}/lua_loader_convert.h
${include_path}/lua_loader_impl.h
)

set(sources
${source_path}/lua_loader.c
${source_path}/lua_loader_convert.c
${source_path}/lua_loader_impl.c
)

Expand Down Expand Up @@ -110,7 +107,7 @@ target_include_directories(${target}
${CMAKE_CURRENT_BINARY_DIR}/include

$<TARGET_PROPERTY:${META_PROJECT_NAME}::metacall,INCLUDE_DIRECTORIES> # MetaCall includes
${LUA_INCLUDE_DIR} # Lua includes (lua.h)
${LUAJIT_INCLUDE_DIR} # LuaJIT includes (lua.h)

PUBLIC
${DEFAULT_INCLUDE_DIRECTORIES}
Expand All @@ -130,8 +127,8 @@ target_link_libraries(${target}
# On macOS, we use dynamic lookup to avoid loading libmetacall twice
$<$<NOT:$<PLATFORM_ID:Darwin>>:${META_PROJECT_NAME}::metacall>

# Lua libraries (both lua and lualib)
${LUA_LIBRARIES}
# LuaJIT library
${LUAJIT_LIBRARY}

PUBLIC
${DEFAULT_LIBRARIES}
Expand Down
45 changes: 45 additions & 0 deletions source/loaders/lua_loader/include/lua_loader/lua_loader_convert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Loader Library by Parra Studios
* A plugin for loading lua code at run-time into a process.
*
* Copyright (C) 2016 - 2026 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef LUA_LOADER_CONVERT_H
#define LUA_LOADER_CONVERT_H 1

#include <lua_loader/lua_loader_api.h>

#include <reflect/reflect_type_id.h>
#include <reflect/reflect_value.h>

#include <lua.h>

#ifdef __cplusplus
extern "C" {
#endif

LUA_LOADER_API int loader_impl_lua_value_to_lua(lua_State *L, value v);

LUA_LOADER_API value loader_impl_lua_lua_to_value(lua_State *L, int index);

LUA_LOADER_API type_id loader_impl_lua_type_from_lua(lua_State *L, int index);

#ifdef __cplusplus
}
#endif

#endif /* LUA_LOADER_CONVERT_H */
Loading