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:
Ian Farmer
2007-07-16 02:37:08 +00:00
parent c65dec54fb
commit 635f127cd0
14 changed files with 69 additions and 11 deletions

View File

@@ -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();
}