2007-06-08 05:11:37 +00:00
|
|
|
package lua.value;
|
|
|
|
|
|
2007-06-14 04:58:09 +00:00
|
|
|
import lua.Lua;
|
2007-07-24 05:06:10 +00:00
|
|
|
import lua.VM;
|
2007-06-08 05:11:37 +00:00
|
|
|
|
|
|
|
|
abstract
|
|
|
|
|
public class LValue {
|
|
|
|
|
|
|
|
|
|
protected static LValue luaUnsupportedOperation() {
|
2007-06-24 15:04:19 +00:00
|
|
|
throw new java.lang.RuntimeException( "not supported" );
|
2007-06-08 05:11:37 +00:00
|
|
|
}
|
2007-06-19 04:25:34 +00:00
|
|
|
|
|
|
|
|
public String id() {
|
|
|
|
|
return Integer.toHexString(hashCode());
|
|
|
|
|
}
|
2007-06-08 05:11:37 +00:00
|
|
|
|
|
|
|
|
// test if value is true
|
|
|
|
|
public boolean luaAsBoolean() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-09-03 00:38:38 +00:00
|
|
|
|
|
|
|
|
/** Return true if this value can be represented as an "int" */
|
|
|
|
|
public boolean isInteger() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-01 04:15:27 +00:00
|
|
|
// perform a lua call, return true if the call is to a lua function, false
|
|
|
|
|
// if it ran to completion.
|
|
|
|
|
public boolean luaStackCall(VM vm) {
|
2007-06-08 05:11:37 +00:00
|
|
|
luaUnsupportedOperation();
|
2007-08-01 04:15:27 +00:00
|
|
|
return false;
|
2007-06-08 05:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unsupported except for numbers
|
|
|
|
|
public LValue luaBinOpUnknown(int opcode, LValue lhs) {
|
|
|
|
|
return luaUnsupportedOperation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unsupported except for numbers
|
|
|
|
|
public LValue luaBinOpInteger(int opcode, int m_value) {
|
|
|
|
|
return luaUnsupportedOperation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unsupported except for numbers
|
|
|
|
|
public LValue luaBinOpDouble(int opcode, double m_value) {
|
|
|
|
|
return luaUnsupportedOperation();
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-14 04:58:09 +00:00
|
|
|
// unsupported except for numbers, strings, and == with various combinations of Nil, Boolean, etc.
|
2007-06-10 19:49:47 +00:00
|
|
|
public boolean luaBinCmpUnknown(int opcode, LValue lhs) {
|
2007-06-14 04:58:09 +00:00
|
|
|
if ( opcode == Lua.OP_EQ )
|
|
|
|
|
return lhs == this;
|
|
|
|
|
luaUnsupportedOperation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unsupported except for strings
|
|
|
|
|
public boolean luaBinCmpString(int opcode, String rhs) {
|
|
|
|
|
if ( opcode == Lua.OP_EQ )
|
|
|
|
|
return false;
|
2007-06-10 19:49:47 +00:00
|
|
|
luaUnsupportedOperation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unsupported except for numbers
|
|
|
|
|
public boolean luaBinCmpInteger(int opcode, int rhs) {
|
2007-06-14 04:58:09 +00:00
|
|
|
if ( opcode == Lua.OP_EQ )
|
|
|
|
|
return false;
|
2007-06-10 19:49:47 +00:00
|
|
|
luaUnsupportedOperation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unsupported except for numbers
|
|
|
|
|
public boolean luaBinCmpDouble(int opcode, double rhs) {
|
2007-06-14 04:58:09 +00:00
|
|
|
if ( opcode == Lua.OP_EQ )
|
|
|
|
|
return false;
|
2007-06-10 19:49:47 +00:00
|
|
|
luaUnsupportedOperation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-08 05:11:37 +00:00
|
|
|
/** set a value in a table
|
2007-07-24 05:06:10 +00:00
|
|
|
* @param vm the calling vm
|
2007-06-17 02:58:40 +00:00
|
|
|
* @param table the table to operate on
|
|
|
|
|
* @param the key to set
|
|
|
|
|
* @param the value to set
|
2007-06-08 05:11:37 +00:00
|
|
|
*/
|
2007-07-24 05:06:10 +00:00
|
|
|
public void luaSetTable(VM vm, LValue table, LValue key, LValue val) {
|
2007-06-08 05:11:37 +00:00
|
|
|
luaUnsupportedOperation();
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-17 02:58:40 +00:00
|
|
|
/** Get a value from a table
|
2007-07-24 05:06:10 +00:00
|
|
|
* @param vm the calling vm
|
|
|
|
|
* @param table the table from which to get the value
|
|
|
|
|
* @param key the key to look up
|
|
|
|
|
*/
|
|
|
|
|
public void luaGetTable(VM vm, LValue table, LValue key) {
|
2007-06-17 02:58:40 +00:00
|
|
|
luaUnsupportedOperation();
|
2007-06-08 05:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get the value as a String
|
|
|
|
|
*/
|
|
|
|
|
public String luaAsString() {
|
|
|
|
|
return super.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Override standard toString with lua String conversion by default */
|
|
|
|
|
public String toString() {
|
|
|
|
|
return luaAsString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Return value as an integer */
|
|
|
|
|
public int luaAsInt() {
|
2007-08-01 06:16:28 +00:00
|
|
|
luaUnsupportedOperation();
|
2007-06-08 05:11:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2007-06-10 19:49:47 +00:00
|
|
|
|
2007-06-24 15:04:19 +00:00
|
|
|
/** Return value as a double */
|
|
|
|
|
public double luaAsDouble() {
|
|
|
|
|
return luaAsInt();
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-10 19:49:47 +00:00
|
|
|
/** Arithmetic negative */
|
|
|
|
|
public LValue luaUnaryMinus() {
|
|
|
|
|
return luaUnsupportedOperation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Built-in opcode LEN, for Strings and Tables */
|
|
|
|
|
public LValue luaLength() {
|
|
|
|
|
// TODO: call meta-method TM_LEN here
|
|
|
|
|
return luaUnsupportedOperation();
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-10 22:53:09 +00:00
|
|
|
/** Valid for tables */
|
|
|
|
|
public LValue luaPairs() {
|
|
|
|
|
return luaUnsupportedOperation();
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-16 15:31:27 +00:00
|
|
|
/** Valid for tables */
|
|
|
|
|
public LValue luaGetMetatable() {
|
|
|
|
|
return luaUnsupportedOperation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Valid for tables */
|
|
|
|
|
public void luaSetMetatable(LValue metatable) {
|
|
|
|
|
luaUnsupportedOperation();
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-16 02:37:08 +00:00
|
|
|
/** Valid for all types: return the type of this value as an LString */
|
|
|
|
|
public abstract LString luaGetType();
|
2007-06-08 05:11:37 +00:00
|
|
|
}
|