From 1e04543de6c80afd8e104b6d1fb14f53be12300c Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Tue, 1 Oct 2024 18:58:23 +0800 Subject: [PATCH] support luajit compile --- CodeFormatLib/CMakeLists.txt | 5 ++++- CodeFormatLib/src/CodeFormatLib.cpp | 9 +++++++++ CodeFormatLib/src/LuaJIT-Compact.cpp | 21 +++++++++++++++++++++ CodeFormatLib/src/LuaJIT-Compact.h | 17 +++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 CodeFormatLib/src/LuaJIT-Compact.cpp create mode 100644 CodeFormatLib/src/LuaJIT-Compact.h diff --git a/CodeFormatLib/CMakeLists.txt b/CodeFormatLib/CMakeLists.txt index b7a3e35..98d7c4b 100644 --- a/CodeFormatLib/CMakeLists.txt +++ b/CodeFormatLib/CMakeLists.txt @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.14) project(CodeFormatLib) -add_library(CodeFormatLib SHARED) +add_library(CodeFormatLib SHARED + src/LuaJIT-Compact.h + src/LuaJIT-Compact.cpp) add_subdirectory(${LuaCodeStyle_SOURCE_DIR}/3rd/lua-5.4.3 lua.out) @@ -20,6 +22,7 @@ target_sources(CodeFormatLib PRIVATE src/CodeFormatLib.cpp src/LuaCodeFormat.cpp + src/LuaJIT-Compact.cpp ) if (NOT WIN32) diff --git a/CodeFormatLib/src/CodeFormatLib.cpp b/CodeFormatLib/src/CodeFormatLib.cpp index 9d5bae4..45d41e6 100644 --- a/CodeFormatLib/src/CodeFormatLib.cpp +++ b/CodeFormatLib/src/CodeFormatLib.cpp @@ -1,5 +1,14 @@ #include "LuaCodeFormat.h" +#ifdef LUAJIT +extern "C" { +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +} +#include "LuaJIT-Compact.h" +#else #include "lua.hpp" +#endif #ifdef _MSC_VER #define EXPORT __declspec(dllexport) diff --git a/CodeFormatLib/src/LuaJIT-Compact.cpp b/CodeFormatLib/src/LuaJIT-Compact.cpp new file mode 100644 index 0000000..0a703d3 --- /dev/null +++ b/CodeFormatLib/src/LuaJIT-Compact.cpp @@ -0,0 +1,21 @@ +#include "LuaJIT-Compact.h" + +#ifdef LUAJIT +int lua_isinteger(lua_State *L, int idx) { + if (lua_type(L, idx) == LUA_TNUMBER) + { + lua_Number n = lua_tonumber(L, idx); + return n == (lua_Integer)n; + } + return 0; +} + +int luaL_len(lua_State *L, int idx) { + return lua_objlen(L, idx); +} + +int lua_geti(lua_State *L, int idx, lua_Integer n) { + lua_rawgeti(L, idx, n); + return lua_type(L, -1); +} +#endif \ No newline at end of file diff --git a/CodeFormatLib/src/LuaJIT-Compact.h b/CodeFormatLib/src/LuaJIT-Compact.h new file mode 100644 index 0000000..ee132bb --- /dev/null +++ b/CodeFormatLib/src/LuaJIT-Compact.h @@ -0,0 +1,17 @@ +#ifndef LUAJIT_COMPACT_H +#define LUAJIT_COMPACT_H + +#ifdef LUAJIT +extern "C" { +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +} + +int lua_isinteger(lua_State *L, int idx); + +int luaL_len(lua_State *L, int idx); + +int lua_geti(lua_State *L, int idx, lua_Integer n); +#endif LUAJIT +#endif //LUAJIT_COMPACT_H