Skip to content

Commit cafd9d6

Browse files
CppCXYtangzx
authored andcommitted
提交lua5.4代码,提供lua5.4的调试
1 parent 766368b commit cafd9d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+29004
-11
lines changed

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ macro(source_group_by_dir proj_dir source_files)
4343
endif(MSVC OR APPLE)
4444
endmacro(source_group_by_dir)
4545

46-
set(EMMY_LUA_VERSION "53" CACHE STRING "Lua version: 51/52/53")
46+
set(EMMY_LUA_VERSION "54" CACHE STRING "Lua version: 51/52/53")
4747

48-
if(${EMMY_LUA_VERSION} STREQUAL "53")
48+
if(${EMMY_LUA_VERSION} STREQUAL "54")
49+
set(EMMY_LUA_DIR "lua-5.4.0")
50+
add_definitions(-DEMMY_LUA_54)
51+
elseif(${EMMY_LUA_VERSION} STREQUAL "53")
4952
set(EMMY_LUA_DIR "lua-5.3.5")
5053
add_definitions(-DEMMY_LUA_53)
5154
elseif(${EMMY_LUA_VERSION} STREQUAL "52")

emmy_core/api/lua_api_loader.cpp

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ IMP_LUA_API(lua_rawget);
8888
IMP_LUA_API(lua_rawset);
8989
IMP_LUA_API(lua_pushlightuserdata);
9090
IMP_LUA_API(lua_touserdata);
91-
IMP_LUA_API(lua_newuserdata);
91+
9292
IMP_LUA_API(lua_rawseti);
9393
IMP_LUA_API(lua_rawgeti);
9494
//51
@@ -108,7 +108,10 @@ IMP_LUA_API_E(lua_pcallk);
108108
IMP_LUA_API_E(luaL_setfuncs);
109109
IMP_LUA_API_E(lua_absindex);
110110
IMP_LUA_API_E(lua_rotate);
111-
111+
//51 & 52 & 53
112+
IMP_LUA_API_E(lua_newuserdata);
113+
//54
114+
IMP_LUA_API_E(lua_newuserdatauv);
112115

113116
int lua_setfenv(lua_State* L, int idx) {
114117
if (luaVersion == LuaVersion::LUA_51) {
@@ -125,6 +128,8 @@ int getDebugEvent(lua_Debug* ar) {
125128
return ar->u.ar52.event;
126129
case LuaVersion::LUA_53:
127130
return ar->u.ar53.event;
131+
case LuaVersion::LUA_54:
132+
return ar->u.ar54.event;
128133
default:
129134
assert(false);
130135
return 0;
@@ -139,6 +144,8 @@ int getDebugCurrentLine(lua_Debug* ar) {
139144
return ar->u.ar52.currentline;
140145
case LuaVersion::LUA_53:
141146
return ar->u.ar53.currentline;
147+
case LuaVersion::LUA_54:
148+
return ar->u.ar54.currentline;
142149
default:
143150
assert(false);
144151
return 0;
@@ -153,6 +160,8 @@ int getDebugLineDefined(lua_Debug* ar) {
153160
return ar->u.ar52.linedefined;
154161
case LuaVersion::LUA_53:
155162
return ar->u.ar53.linedefined;
163+
case LuaVersion::LUA_54:
164+
return ar->u.ar54.linedefined;
156165
default:
157166
assert(false);
158167
return 0;
@@ -167,6 +176,8 @@ const char* getDebugSource(lua_Debug* ar) {
167176
return ar->u.ar52.source;
168177
case LuaVersion::LUA_53:
169178
return ar->u.ar53.source;
179+
case LuaVersion::LUA_54:
180+
return ar->u.ar54.source;
170181
default:
171182
assert(false);
172183
return nullptr;
@@ -181,6 +192,8 @@ const char* getDebugName(lua_Debug* ar) {
181192
return ar->u.ar52.name;
182193
case LuaVersion::LUA_53:
183194
return ar->u.ar53.name;
195+
case LuaVersion::LUA_54:
196+
return ar->u.ar54.name;
184197
default:
185198
assert(false);
186199
return nullptr;
@@ -245,6 +258,8 @@ void luaL_setfuncs(lua_State* L, const luaL_Reg* l, int nup) {
245258
}
246259

247260
int lua_upvalueindex(int i) {
261+
if (luaVersion == LuaVersion::LUA_54)
262+
return -1001000 - i;
248263
if (luaVersion == LuaVersion::LUA_53)
249264
return -1001000 - i;
250265
if (luaVersion == LuaVersion::LUA_52)
@@ -272,6 +287,18 @@ void lua_remove(lua_State *L, int idx) {
272287
}
273288
}
274289

290+
void lua_newuserdata(lua_State* L, int size)
291+
{
292+
if(luaVersion == LuaVersion::LUA_51 || luaVersion == LuaVersion::LUA_52 || luaVersion == LuaVersion::LUA_53)
293+
{
294+
e_lua_newuserdata(L, size);
295+
}
296+
else
297+
{
298+
e_lua_newuserdatauv(L, size, 1);
299+
}
300+
}
301+
275302
extern "C" bool SetupLuaAPI() {
276303
LOAD_LUA_API(lua_gettop);
277304
LOAD_LUA_API(lua_settop);
@@ -306,7 +333,7 @@ extern "C" bool SetupLuaAPI() {
306333
LOAD_LUA_API(lua_rawset);
307334
LOAD_LUA_API(lua_pushlightuserdata);
308335
LOAD_LUA_API(lua_touserdata);
309-
LOAD_LUA_API(lua_newuserdata);
336+
310337
LOAD_LUA_API(lua_rawseti);
311338
LOAD_LUA_API(lua_rawgeti);
312339
//51
@@ -326,10 +353,20 @@ extern "C" bool SetupLuaAPI() {
326353
LOAD_LUA_API_E(lua_pcallk);
327354
LOAD_LUA_API_E(luaL_setfuncs);
328355
LOAD_LUA_API_E(lua_absindex);
356+
// 51 & 52 & 53
357+
LOAD_LUA_API_E(lua_newuserdata);
329358
//53
330359
LOAD_LUA_API_E(lua_rotate);
331-
332-
if (e_lua_rotate) {
360+
//54
361+
LOAD_LUA_API_E(lua_newuserdatauv);
362+
363+
if(e_lua_newuserdatauv)
364+
{
365+
luaVersion = LuaVersion::LUA_54;
366+
LUA_REGISTRYINDEX = -1001000;
367+
LUA_GLOBALSINDEX = 2;
368+
}
369+
else if (e_lua_rotate) {
333370
luaVersion = LuaVersion::LUA_53;
334371
LUA_REGISTRYINDEX = -1001000;
335372
LUA_GLOBALSINDEX = 2;

emmy_core/api/lua_api_loader.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,33 @@ struct lua_Debug_53 {
154154
struct CallInfo *i_ci; /* active function */
155155
};
156156

157+
struct lua_Debug_54 {
158+
int event;
159+
const char* name; /* (n) */
160+
const char* namewhat; /* (n) 'global', 'local', 'field', 'method' */
161+
const char* what; /* (S) 'Lua', 'C', 'main', 'tail' */
162+
const char* source; /* (S) */
163+
size_t srclen; /* (S) */
164+
int currentline; /* (l) */
165+
int linedefined; /* (S) */
166+
int lastlinedefined; /* (S) */
167+
unsigned char nups; /* (u) number of upvalues */
168+
unsigned char nparams;/* (u) number of parameters */
169+
char isvararg; /* (u) */
170+
char istailcall; /* (t) */
171+
unsigned short ftransfer; /* (r) index of first value transferred */
172+
unsigned short ntransfer; /* (r) number of transferred values */
173+
char short_src[LUA_IDSIZE]; /* (S) */
174+
/* private part */
175+
struct CallInfo* i_ci; /* active function */
176+
};
177+
157178
struct lua_Debug {
158179
union {
159180
lua_Debug_51 ar51;
160181
lua_Debug_52 ar52;
161182
lua_Debug_53 ar53;
183+
lua_Debug_54 ar54;
162184
} u;
163185
};
164186

@@ -281,8 +303,6 @@ typedef void(*dll_lua_pushlightuserdata)(lua_State *L, void *p);
281303
DEF_LUA_API(lua_pushlightuserdata);
282304
typedef void*(*dll_lua_touserdata)(lua_State *L, int idx);
283305
DEF_LUA_API(lua_touserdata);
284-
typedef void*(*dll_lua_newuserdata)(lua_State *L, int size);
285-
DEF_LUA_API(lua_newuserdata);
286306
typedef void*(*dll_lua_rawseti)(lua_State *L, int idx, lua_Integer n);
287307
DEF_LUA_API(lua_rawseti);
288308
typedef void*(*dll_lua_rawgeti)(lua_State *L, int idx, lua_Integer n);
@@ -319,10 +339,17 @@ typedef void (*dll_e_luaL_setfuncs)(lua_State* L, const luaL_Reg* l, int nup);
319339
DEF_LUA_API_E(luaL_setfuncs);
320340
typedef int(*dll_e_lua_absindex)(lua_State *L, int idx);
321341
DEF_LUA_API_E(lua_absindex);
342+
// 51 & 52 & 53
343+
typedef void* (*dll_e_lua_newuserdata)(lua_State* L, int size);
344+
DEF_LUA_API_E(lua_newuserdata);
322345
//53
323346
typedef void (*dll_e_lua_rotate)(lua_State *L, int idx, int n);
324347
DEF_LUA_API_E(lua_rotate);
325348

349+
//54
350+
typedef void* (*dll_e_lua_newuserdatauv)(lua_State* L, int size, int nuvalue);
351+
DEF_LUA_API_E(lua_newuserdatauv);
352+
326353
lua_Integer lua_tointeger(lua_State* L, int idx);
327354
lua_Number lua_tonumber(lua_State* L, int idx);
328355
int lua_setfenv(lua_State* L, int idx);
@@ -333,4 +360,5 @@ int lua_upvalueindex(int i);
333360
int lua_absindex(lua_State *L, int idx);
334361
void lua_call(lua_State* L, int nargs, int nresults);
335362
void luaL_setfuncs(lua_State* L, const luaL_Reg* l, int nup);
336-
void lua_remove(lua_State *L, int idx);
363+
void lua_remove(lua_State *L, int idx);
364+
void lua_newuserdata(lua_State* L, int size);

emmy_core/emmy_core.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ LuaVersion luaVersion = LuaVersion::LUA_51;
128128
LuaVersion luaVersion = LuaVersion::LUA_52;
129129
#elif EMMY_LUA_53
130130
LuaVersion luaVersion = LuaVersion::LUA_53;
131+
#elif EMMY_LUA_54
132+
LuaVersion luaVersion = LuaVersion::LUA_54;
131133
#else
132134
LuaVersion luaVersion = LuaVersion::UNKNOWN;
133135
#endif

emmy_core/emmy_core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ enum class LuaVersion {
3030
UNKNOWN,
3131
LUA_51 = 51,
3232
LUA_52 = 52,
33-
LUA_53 = 53
33+
LUA_53 = 53,
34+
LUA_54 = 54
3435
};
3536

3637
extern LuaVersion luaVersion;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cmake_minimum_required(VERSION 3.7)
2+
3+
project (lua54)
4+
set(LUA_NAME "lua54")
5+
set(LINK_LIBRARIES ${LUA_NAME}_dll)
6+
7+
8+
if(WIN32)
9+
add_definitions( -D_CRT_SECURE_NO_WARNINGS )
10+
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
11+
add_definitions( -DLUA_USE_LINUX )
12+
list(APPEND LINK_LIBRARIES readline dl m)
13+
else()
14+
add_definitions( -DLUA_USE_MACOSX )
15+
list(APPEND LINK_LIBRARIES readline)
16+
endif()
17+
18+
file(GLOB HEADER_LIST "src/*.h" "src/lua.hpp")
19+
aux_source_directory(src SRC_LIST)
20+
list(REMOVE_ITEM SRC_LIST "src/lua.c" "src/luac.c")
21+
22+
# 2. lua static library
23+
if(WIN32)
24+
add_definitions(-DLUA_BUILD_AS_DLL)
25+
endif(WIN32)
26+
27+
add_library (${LUA_NAME}_a STATIC ${SRC_LIST} ${HEADER_LIST})
28+
29+
# add_library (${LUA_NAME}_dll SHARED ${SRC_LIST} ${HEADER_LIST})
30+
# set_target_properties(${LUA_NAME}_dll PROPERTIES OUTPUT_NAME "lua")
31+
32+
# add_executable(${LUA_NAME} "src/lua.c")
33+
# target_link_libraries(${LUA_NAME} ${LUA_NAME}_dll)
34+
# set_target_properties(${LUA_NAME} PROPERTIES OUTPUT_NAME "lua")

0 commit comments

Comments
 (0)