Skip to content

Commit 1e04543

Browse files
committed
support luajit compile
1 parent e728970 commit 1e04543

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

CodeFormatLib/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.14)
22

33
project(CodeFormatLib)
44

5-
add_library(CodeFormatLib SHARED)
5+
add_library(CodeFormatLib SHARED
6+
src/LuaJIT-Compact.h
7+
src/LuaJIT-Compact.cpp)
68

79

810
add_subdirectory(${LuaCodeStyle_SOURCE_DIR}/3rd/lua-5.4.3 lua.out)
@@ -20,6 +22,7 @@ target_sources(CodeFormatLib
2022
PRIVATE
2123
src/CodeFormatLib.cpp
2224
src/LuaCodeFormat.cpp
25+
src/LuaJIT-Compact.cpp
2326
)
2427

2528
if (NOT WIN32)

CodeFormatLib/src/CodeFormatLib.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#include "LuaCodeFormat.h"
2+
#ifdef LUAJIT
3+
extern "C" {
4+
#include "lua.h"
5+
#include "lualib.h"
6+
#include "lauxlib.h"
7+
}
8+
#include "LuaJIT-Compact.h"
9+
#else
210
#include "lua.hpp"
11+
#endif
312

413
#ifdef _MSC_VER
514
#define EXPORT __declspec(dllexport)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "LuaJIT-Compact.h"
2+
3+
#ifdef LUAJIT
4+
int lua_isinteger(lua_State *L, int idx) {
5+
if (lua_type(L, idx) == LUA_TNUMBER)
6+
{
7+
lua_Number n = lua_tonumber(L, idx);
8+
return n == (lua_Integer)n;
9+
}
10+
return 0;
11+
}
12+
13+
int luaL_len(lua_State *L, int idx) {
14+
return lua_objlen(L, idx);
15+
}
16+
17+
int lua_geti(lua_State *L, int idx, lua_Integer n) {
18+
lua_rawgeti(L, idx, n);
19+
return lua_type(L, -1);
20+
}
21+
#endif

CodeFormatLib/src/LuaJIT-Compact.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef LUAJIT_COMPACT_H
2+
#define LUAJIT_COMPACT_H
3+
4+
#ifdef LUAJIT
5+
extern "C" {
6+
#include "lua.h"
7+
#include "lualib.h"
8+
#include "lauxlib.h"
9+
}
10+
11+
int lua_isinteger(lua_State *L, int idx);
12+
13+
int luaL_len(lua_State *L, int idx);
14+
15+
int lua_geti(lua_State *L, int idx, lua_Integer n);
16+
#endif LUAJIT
17+
#endif //LUAJIT_COMPACT_H

0 commit comments

Comments
 (0)