-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
315829c
commit 3aea236
Showing
7 changed files
with
175 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,32 @@ | ||
package org.itsallcode.luava; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
|
||
import org.itsallcode.luava.ffi.Lua; | ||
|
||
public class LuaFunction { | ||
|
||
private final MemorySegment state; | ||
private final LuaStack stack; | ||
private final LowLevelLua lowLevelLua; | ||
private final Arena arena; | ||
private final int idx; | ||
private final int errorHandlerIdx; | ||
|
||
LuaFunction(final MemorySegment state, final LuaStack stack, final Arena arena, final int idx) { | ||
this.state = state; | ||
this.stack = stack; | ||
LuaFunction(final LowLevelLua lowLevelLua, final Arena arena, final int idx, final int errorHandlerIdx) { | ||
this.lowLevelLua = lowLevelLua; | ||
this.arena = arena; | ||
this.idx = idx; | ||
this.errorHandlerIdx = errorHandlerIdx; | ||
} | ||
|
||
public void addArgInteger(final int value) { | ||
stack.pushInteger(value); | ||
lowLevelLua.stack().pushInteger(value); | ||
} | ||
|
||
public void call(final int nargs, final int nresults) { | ||
call(nargs, nresults, 0, 0, Lua.NULL()); | ||
} | ||
|
||
private void call(final int nargs, final int nresults, final int errfunc, final long ctx, final MemorySegment k) { | ||
final int status = Lua.lua_pcallk(state, nargs, nresults, errfunc, ctx, k); | ||
if (status != Lua.LUA_OK()) { | ||
final String errorMessage = stack.toString(-1); | ||
stack.pop(1); | ||
throw new FunctionCallException("lua_pcallk", status, errorMessage); | ||
} | ||
lowLevelLua.pcall(nargs, nresults, errorHandlerIdx); | ||
} | ||
|
||
public long getIntegerResult() { | ||
final long value = stack.toInteger(-1); | ||
stack.pop(1); | ||
final long value = lowLevelLua.stack().toInteger(-1); | ||
lowLevelLua.stack().pop(1); | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.itsallcode.luava; | ||
|
||
import org.junit.jupiter.api.*; | ||
|
||
class LowLevelLuaTest { | ||
private LowLevelLua lua; | ||
|
||
@BeforeEach | ||
void setup() { | ||
lua = LowLevelLua.create(); | ||
} | ||
|
||
@AfterEach | ||
void stop() { | ||
lua.close(); | ||
} | ||
|
||
@Test | ||
void functionWithErrorLeavesStackEmpty() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters