Skip to content

Commit

Permalink
Make LuaNatives a public interface
Browse files Browse the repository at this point in the history
- Remove duplicates of lua_pcall functions
- Remove luaL_gsub
  • Loading branch information
gudzpoz committed May 23, 2024
1 parent 0d0aefc commit aa9b5d7
Show file tree
Hide file tree
Showing 27 changed files with 1,090 additions and 1,741 deletions.
9 changes: 1 addition & 8 deletions example/src/test/java/party/iroiro/luajava/JuaApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,9 @@ private void convertTableTest(Lua L) {
L.pop(1);
}

private static class NativeTest extends Lua51Natives {
@Override
public long lua_newuserdata(long ptr, long size) {
return super.lua_newuserdata(ptr, size);
}
}

private void convertUserdataTest() {
Lua L = new Lua51();
assertNotEquals(0, new NativeTest()
assertNotEquals(0, ((Lua51Natives) L.getLuaNative())
.lua_newuserdata(L.getPointer(), 1024));
assertThrows(IllegalArgumentException.class,
() -> JuaAPI.convertFromLua(L, Integer.class, -1),
Expand Down
11 changes: 4 additions & 7 deletions example/src/test/java/party/iroiro/luajava/luaj/LuaJTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,10 @@ public void testLuaJCoroutine() {
public void luaJNativesUserDataTest() {
try (LuaJ L = new LuaJ()) {
Object object = new Object();
new LuaJNatives() {
{
lua_newuserdata(L.getPointer(), object);
assertEquals(USERDATA, L.type(-1));
L.setGlobal("customObject");
}
};
LuaJNatives C = (LuaJNatives) L.getLuaNative();
C.lua_newuserdata(L.getPointer(), object);
assertEquals(USERDATA, L.type(-1));
L.setGlobal("customObject");
L.set("object", object);
L.run("assert(object ~= customObject)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,17 @@ public static boolean isAndroid() {
new ScriptTester("/suite/otherConvTest.lua", L -> {
L.push(new OtherTypes(), Lua.Conversion.NONE);
L.setGlobal("others");
LuaNative C = L.getLuaNative();
LuaNatives C = L.getLuaNative();
if (C instanceof Lua51Natives) {
new Lua51Natives() {
{
lua_newuserdata(L.getPointer(), 1024);
}
};
((Lua51Natives) C).lua_newuserdata(L.getPointer(), 1024);
} else if (C instanceof Lua52Natives) {
new Lua52Natives() {
{
lua_newuserdata(L.getPointer(), 1024);
}
};
((Lua52Natives) C).lua_newuserdata(L.getPointer(), 1024);
} else if (C instanceof Lua53Natives) {
new Lua53Natives() {
{
lua_newuserdata(L.getPointer(), 1024);
}
};
((Lua53Natives) C).lua_newuserdata(L.getPointer(), 1024);
} else if (C instanceof Lua54Natives) {
new Lua54Natives() {
{
lua_newuserdatauv(L.getPointer(), 1024, 0);
}
};
((Lua54Natives) C).lua_newuserdatauv(L.getPointer(), 1024, 0);
} else if (C instanceof LuaJitNatives) {
new LuaJitNatives() {
{
lua_newuserdata(L.getPointer(), 1024);
}
};
((LuaJitNatives) C).lua_newuserdata(L.getPointer(), 1024);
} else if (C.getClass().getName().endsWith("LuaJNatives")) {
// This is tested instead in NativesTest,
// because our Android build has trouble desugaring and cannot run LuaJ.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ private void testLuaToJavaConversions() {
}
L.pop(expected.length);

LuaNative luaNative = L.getLuaNative();
LuaNatives luaNative = L.getLuaNative();

luaNative.lua_pushlightuserdata(L.getPointer(), 0);
assertEquals(LIGHTUSERDATA, L.type(-1));
Expand Down Expand Up @@ -832,7 +832,7 @@ private void assertIterableEquals(Iterable<?> a, Iterable<?> b) {
}
}

private void testToMap(LuaNative luaNative) {
private void testToMap(LuaNatives luaNative) {
L.push(true);
assertNull(L.toMap(-1));
HashMap<Object, Object> emptyMap = new HashMap<>();
Expand Down
4 changes: 0 additions & 4 deletions lua51/jni/mod/luacomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ static int luaJ_dobuffer(lua_State * L, unsigned char * buffer, int size, const
return (luaL_loadbuffer(L, (const char *) buffer, size, name) || lua_pcall(L, 0, LUA_MULTRET, 0));
}

static int luaJ_pcall(lua_State * L, int nargs, int nresults) {
return lua_pcall(L, nargs, nresults, 0);
}

static int luaJ_resume(lua_State * L, int narg) {
return lua_resume(L, narg);
}
Expand Down
4 changes: 2 additions & 2 deletions lua51/src/main/java/party/iroiro/luajava/lua51/Lua51.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import party.iroiro.luajava.AbstractLua;
import party.iroiro.luajava.LuaException;
import party.iroiro.luajava.LuaException.LuaError;
import party.iroiro.luajava.LuaNative;
import party.iroiro.luajava.LuaNatives;

import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -50,7 +50,7 @@ protected Lua51(long L, int id, AbstractLua main) {
super(main.getLuaNative(), L, id, main);
}

private static LuaNative getNatives() throws LinkageError {
private static LuaNatives getNatives() throws LinkageError {
synchronized (natives) {
if (natives.get() == null) {
try {
Expand Down
Loading

0 comments on commit aa9b5d7

Please sign in to comment.