Skip to content

Commit 4117805

Browse files
committed
chore: minor tweaks for build
1 parent 3cf6eb6 commit 4117805

4 files changed

Lines changed: 183 additions & 137 deletions

File tree

native/luau

src/main/java/net/hollowcube/luau/LuaState.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,11 @@ static LuaState wrap(MemorySegment L) {
296296
Object checkUserData(int argNum, String typeName);
297297
ByteBuffer checkBuffer(int argNum);
298298

299-
// LUALIB_API void luaL_register(lua_State* L, const char* libname, const luaL_Reg* l);
300299
// LUALIB_API int luaL_getmetafield(lua_State* L, int obj, const char* e);
301300
// LUALIB_API int luaL_callmeta(lua_State* L, int obj, const char* e);
302301

303-
// LUALIB_API int luaL_newmetatable(lua_State* L, const char* tname);
304-
// #define luaL_getmetatable(L, n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
302+
boolean newMetaTable(String typeName);
303+
LuaType getMetaTable(String typeName);
305304

306305
// TODO: idk below
307306
// LUALIB_API void luaL_where(lua_State* L, int lvl);

src/main/java/net/hollowcube/luau/LuaStateImpl.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ record LuaStateImpl(MemorySegment L) implements LuaState {
4747
NativeLibraryLoader.loadLibrary("vm");
4848

4949
if ("dump".equals(ASSERT_HANDLER)) {
50-
luaW_assertconf_log.makeInvoker().apply();
51-
} else if ("log".equals(ASSERT_HANDLER)) {
5250
luaW_assertconf_dump.makeInvoker().apply();
51+
} else if ("log".equals(ASSERT_HANDLER)) {
52+
luaW_assertconf_log.makeInvoker().apply();
5353
}
5454
}
5555

@@ -778,7 +778,10 @@ public int yield(int nresults) {
778778
@Override
779779
public LuaStatus resume(@Nullable LuaState from, int narg) {
780780
final MemorySegment fromL = from != null ? ((LuaStateImpl) from).L : MemorySegment.NULL;
781-
return LuaStatus.byId(lua_resume(L, fromL, narg));
781+
final LuaStatus status = LuaStatus.byId(lua_resume(L, fromL, narg));
782+
if (status != LuaStatus.OK && status != LuaStatus.YIELD)
783+
propagateExceptionInner(status);
784+
return status;
782785
}
783786

784787
//TODO: test me
@@ -1113,6 +1116,20 @@ public ByteBuffer checkBuffer(int argNum) {
11131116

11141117
//endregion
11151118

1119+
@Override
1120+
public boolean newMetaTable(String typeName) {
1121+
try (var arena = Arena.ofConfined()) {
1122+
final int result = luaLW_newmetatable(L, arena.allocateFrom(typeName));
1123+
propagateException();
1124+
return result != 0;
1125+
}
1126+
}
1127+
1128+
@Override
1129+
public LuaType getMetaTable(String typeName) {
1130+
return getField(REGISTRY_INDEX, typeName);
1131+
}
1132+
11161133
@Override
11171134
public @Nullable String findTable(int index, String fieldName, int sizeHint) {
11181135
try (Arena arena = Arena.ofConfined()) {
@@ -1306,12 +1323,7 @@ static StackTraceElement[] mergeBacktrace(
13061323
luaTraceIndex = readLuaTracePart(L, luaElem, mergedTrace, luaTraceIndex) - 1;
13071324

13081325
for (final StackTraceElement javaElem : javaTrace) {
1309-
// lua_h.lua_pcall is our downcall marker, we expect no other downcalls to occur.
1310-
// At every downcall point, we need to get the 'next' lua trace segment.
1311-
boolean isDowncall =
1312-
lua_h.class.getName().equals(javaElem.getClassName()) && "lua_pcall".equals(
1313-
javaElem.getMethodName());
1314-
if (isDowncall) {
1326+
if (isDowncall(javaElem)) {
13151327
luaTraceIndex = readLuaTracePart(L, luaElem, mergedTrace, luaTraceIndex);
13161328
}
13171329

@@ -1321,6 +1333,16 @@ static StackTraceElement[] mergeBacktrace(
13211333
return mergedTrace.toArray(new StackTraceElement[0]);
13221334
}
13231335

1336+
private static boolean isDowncall(StackTraceElement elem) {
1337+
// lua_h.lua_pcall is our downcall marker, we expect no other downcalls to occur.
1338+
// At every downcall point, we need to get the 'next' lua trace segment.
1339+
if (lua_h.class.getName().equals(elem.getClassName())
1340+
&& "lua_pcall".equals(elem.getMethodName())) return true;
1341+
if (LuaStateImpl.class.getName().equals(elem.getClassName())
1342+
&& "resume".equals(elem.getMethodName())) return true;
1343+
return false;
1344+
}
1345+
13241346
private static int readLuaTracePart(
13251347
MemorySegment L, MemorySegment luaElem,
13261348
List<StackTraceElement> mergedTrace,
@@ -1362,7 +1384,8 @@ class Exclusions {
13621384
LuaStateImpl.class.getName() +
13631385
"-propagateException", LuaStateImpl.class.getName() +
13641386
"-propagateExceptionInner",
1365-
LuaStateImpl.class.getName() + "-pcallErrFunc");
1387+
LuaStateImpl.class.getName() + "-pcallErrFunc",
1388+
LuaStateImpl.class.getName() + "-lambda$static$2");
13661389
}
13671390
return Exclusions.SET.contains("%s-%s".formatted(elem.getClassName(),
13681391
elem.getMethodName()));

0 commit comments

Comments
 (0)