Initial draft of interpreter. Lua compiled "chunks" can be unmarshalled. Approximately half of bytecodes implemented in some form or another.
This commit is contained in:
33
src/main/java/lua/Builtin.java
Normal file
33
src/main/java/lua/Builtin.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package lua;
|
||||
|
||||
import lua.value.LFunction;
|
||||
import lua.value.LString;
|
||||
import lua.value.LTable;
|
||||
|
||||
final class Builtin extends LFunction {
|
||||
|
||||
static void addBuiltins(LTable table) {
|
||||
table.luaSetTable( new LString( "print" ), new Builtin(0) );
|
||||
}
|
||||
|
||||
private static final int PRINT = 0;
|
||||
private int id;
|
||||
Builtin( int id ) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
// perform a lua call
|
||||
public void luaStackCall(StackState state, int base, int nresults) {
|
||||
switch ( id ) {
|
||||
case PRINT:
|
||||
System.out.println( String.valueOf( state.stack[base+1] ) );
|
||||
return;
|
||||
default:
|
||||
luaUnsupportedOperation();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user