Skip to content

Commit db8d57f

Browse files
committed
Fix lua5.5 support
1 parent 1845620 commit db8d57f

File tree

5 files changed

+47
-61
lines changed

5 files changed

+47
-61
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
| Lua 5.2 || Fully supported |
3535
| Lua 5.3 || Fully supported |
3636
| Lua 5.4 || Fully supported |
37+
| Lua 5.5 || Fully supported |
3738
| LuaJIT || Fully supported |
3839

3940
## 🚀 Quick Start
@@ -97,14 +98,14 @@ print("Hello, EmmyLua Debugger!")
9798

9899
| Option | Default | Description |
99100
|-----------------------|---------|------------------------------------|
100-
| `EMMY_LUA_VERSION` | `54` | Lua version (51/52/53/54/jit) |
101+
| `EMMY_LUA_VERSION` | `55` | Lua version (51/52/53/54/55/jit) |
101102
| `EMMY_USE_LUA_SOURCE` | `OFF` | Whether to build with Lua source |
102103

103104
### Advanced Build Examples
104105

105106
```bash
106107
# Build for a specific version
107-
cmake .. -DEMMY_LUA_VERSION=53
108+
cmake .. -DEMMY_LUA_VERSION=55
108109
# Build using Lua source
109110
cmake .. -DEMMY_USE_LUA_SOURCE=ON
110111
```

build_script/lua_exe/CMakeLists.txt

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ elseif(${EMMY_LUA_VERSION} STREQUAL "51")
1919
endif()
2020

2121
option(LUA_BUILD_AS_DLL "USE" ON)
22-
set(lua_dll_SOURCE_DIR "../../third-party/${EMMY_LUA_DIR}")
22+
set(lua_dll_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../third-party/${EMMY_LUA_DIR}")
2323

2424
add_subdirectory("${lua_dll_SOURCE_DIR}" luadll.out)
2525

@@ -33,54 +33,8 @@ target_sources(lua PUBLIC
3333

3434
target_link_libraries(lua "lua${EMMY_LUA_VERSION}")
3535

36-
# Add luac executable
37-
add_executable(luac)
38-
39-
target_sources(luac PRIVATE
40-
${lua_dll_SOURCE_DIR}/src/luac.c
41-
# Lua core library sources (required for luac)
42-
${lua_dll_SOURCE_DIR}/src/lapi.c
43-
${lua_dll_SOURCE_DIR}/src/lcode.c
44-
${lua_dll_SOURCE_DIR}/src/lctype.c
45-
${lua_dll_SOURCE_DIR}/src/ldebug.c
46-
${lua_dll_SOURCE_DIR}/src/ldo.c
47-
${lua_dll_SOURCE_DIR}/src/ldump.c
48-
${lua_dll_SOURCE_DIR}/src/lfunc.c
49-
${lua_dll_SOURCE_DIR}/src/lgc.c
50-
${lua_dll_SOURCE_DIR}/src/llex.c
51-
${lua_dll_SOURCE_DIR}/src/lmem.c
52-
${lua_dll_SOURCE_DIR}/src/lobject.c
53-
${lua_dll_SOURCE_DIR}/src/lopcodes.c
54-
${lua_dll_SOURCE_DIR}/src/lparser.c
55-
${lua_dll_SOURCE_DIR}/src/lstate.c
56-
${lua_dll_SOURCE_DIR}/src/lstring.c
57-
${lua_dll_SOURCE_DIR}/src/ltable.c
58-
${lua_dll_SOURCE_DIR}/src/ltm.c
59-
${lua_dll_SOURCE_DIR}/src/lundump.c
60-
${lua_dll_SOURCE_DIR}/src/lvm.c
61-
${lua_dll_SOURCE_DIR}/src/lzio.c
62-
${lua_dll_SOURCE_DIR}/src/lauxlib.c
63-
)
64-
65-
if(WIN32)
66-
target_compile_definitions(luac PRIVATE _CRT_SECURE_NO_WARNINGS)
67-
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
68-
target_compile_definitions(luac PRIVATE LUA_USE_LINUX)
69-
target_link_libraries(luac m dl)
70-
else()
71-
target_compile_definitions(luac PRIVATE LUA_USE_MACOSX)
72-
target_link_libraries(luac m)
73-
endif()
74-
75-
76-
install(
77-
TARGETS lua luac
78-
LIBRARY DESTINATION ./
79-
RUNTIME DESTINATION ./
80-
)
81-
8236
install(
83-
TARGETS "lua${EMMY_LUA_VERSION}"
37+
TARGETS lua "lua${EMMY_LUA_VERSION}"
8438
LIBRARY DESTINATION ./
8539
RUNTIME DESTINATION ./
8640
)

emmy_debugger/src/api/lua_api_loader.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,20 @@ void luaL_setfuncs(lua_State* L, const luaL_Reg* l, int nup)
318318

319319
int lua_upvalueindex(int i)
320320
{
321-
if (luaVersion == LuaVersion::LUA_54)
322-
return -1001000 - i;
323-
if (luaVersion == LuaVersion::LUA_53)
324-
return -1001000 - i;
325-
if (luaVersion == LuaVersion::LUA_52)
326-
return -1001000 - i;
321+
switch (luaVersion) {
322+
case LuaVersion::LUA_55: {
323+
return LUA_REGISTRYINDEX - i;
324+
}
325+
case LuaVersion::LUA_52:
326+
case LuaVersion::LUA_53:
327+
case LuaVersion::LUA_54: {
328+
return -1001000 - i;
329+
}
330+
default: {
331+
return -10002 - i;
332+
}
333+
}
334+
327335
return -10002 - i;
328336
}
329337

emmy_debugger/src/debugger/emmy_debugger.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,31 @@ bool Debugger::DoEval(std::shared_ptr<EvalContext> evalContext) {
963963
// 如果是 aaa:bbbb 则纠正为aaa.bbbb
964964
int r = luaL_loadstring(L, statement.c_str());
965965
if (r == LUA_ERRSYNTAX) {
966-
evalContext->error = "syntax err: ";
967-
evalContext->error.append(evalContext->expr);
968-
return false;
966+
// 尝试将 : 替换为 . 后重新加载
967+
std::string correctedExpr = evalContext->expr;
968+
size_t colonPos = correctedExpr.find(':');
969+
if (colonPos != std::string::npos) {
970+
correctedExpr[colonPos] = '.';
971+
std::string correctedStatement = "return ";
972+
if (evalContext->setValue) {
973+
correctedStatement = correctedExpr + " = " + evalContext->value + " return " + correctedExpr;
974+
} else {
975+
correctedStatement.append(correctedExpr);
976+
}
977+
lua_pop(L, 1); // 弹出之前的错误信息
978+
r = luaL_loadstring(L, correctedStatement.c_str());
979+
if (r == LUA_OK) {
980+
// 纠正成功,继续执行
981+
evalContext->expr = correctedExpr; // 更新表达式
982+
}
983+
}
984+
985+
if (r == LUA_ERRSYNTAX) {
986+
lua_pop(L, 1); // 弹出错误信息
987+
evalContext->error = "syntax err: ";
988+
evalContext->error.append(evalContext->expr);
989+
return false;
990+
}
969991
}
970992
// call
971993
const int fIdx = lua_gettop(L);
@@ -977,7 +999,8 @@ bool Debugger::DoEval(std::shared_ptr<EvalContext> evalContext) {
977999
lua_setfenv(L, fIdx);
9781000
#elif defined(EMMY_LUA_51) || defined(EMMY_LUA_JIT)
9791001
lua_setfenv(L, fIdx);
980-
#else //52 & 53
1002+
#else //52, 53, 54, 55+
1003+
// Lua 5.2+ 使用 _ENV upvalue 替代 setfenv
9811004
lua_setupvalue(L, fIdx, 1);
9821005
#endif
9831006
assert(lua_gettop(L) == fIdx);

third-party/libuv-1.46.0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.4)
1+
cmake_minimum_required(VERSION 3.11)
22

33
if(POLICY CMP0091)
44
cmake_policy(SET CMP0091 NEW) # Enable MSVC_RUNTIME_LIBRARY setting

0 commit comments

Comments
 (0)