Add new built-in function type() that returns the name of the type of
the given value as a string. Includes test case.
This commit is contained in:
@@ -21,8 +21,9 @@ final class Builtin extends LFunction {
|
||||
private static final int PAIRS = 1;
|
||||
private static final int GETMETATABLE = 2;
|
||||
private static final int SETMETATABLE = 3;
|
||||
private static final int TYPE = 4;
|
||||
|
||||
private static final String[] NAMES = { "print", "pairs", "getmetatable", "setmetatable" };
|
||||
private static final String[] NAMES = { "print", "pairs", "getmetatable", "setmetatable", "type" };
|
||||
|
||||
private static PrintStream stdout = System.out;
|
||||
|
||||
@@ -62,6 +63,10 @@ final class Builtin extends LFunction {
|
||||
call.stack[base] = call.stack[base+1];
|
||||
call.top = base+1;
|
||||
break;
|
||||
case TYPE:
|
||||
call.stack[base] = call.stack[base+1].luaGetType();
|
||||
call.top = base+1;
|
||||
break;
|
||||
default:
|
||||
luaUnsupportedOperation();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user