Skip to content

Commit

Permalink
support luajit compile
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Oct 1, 2024
1 parent e728970 commit 1e04543
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CodeFormatLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -20,6 +22,7 @@ target_sources(CodeFormatLib
PRIVATE
src/CodeFormatLib.cpp
src/LuaCodeFormat.cpp
src/LuaJIT-Compact.cpp
)

if (NOT WIN32)
Expand Down
9 changes: 9 additions & 0 deletions CodeFormatLib/src/CodeFormatLib.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
21 changes: 21 additions & 0 deletions CodeFormatLib/src/LuaJIT-Compact.cpp
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions CodeFormatLib/src/LuaJIT-Compact.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1e04543

Please sign in to comment.