-
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
kaklakariada
committed
Sep 20, 2024
1 parent
2e6954a
commit bf580de
Showing
4 changed files
with
81 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.itsallcode.jlua; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
|
||
import org.itsallcode.jlua.ffi.Lua; | ||
|
||
public class LuaFunction { | ||
|
||
private final MemorySegment state; | ||
private final LuaStack stack; | ||
private final Arena arena; | ||
private final int idx; | ||
|
||
LuaFunction(final MemorySegment state, final LuaStack stack, final Arena arena, final int idx) { | ||
this.state = state; | ||
this.stack = stack; | ||
this.arena = arena; | ||
this.idx = idx; | ||
} | ||
|
||
public void addArgInteger(final int value) { | ||
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); | ||
} | ||
} | ||
|
||
public long getIntegerResult() { | ||
final long value = stack.toInteger(-1); | ||
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