added type() top-level Lua function like the one in the basic package

git-svn-id: svn://anubis/anaglym/trunk@228 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-01-28 05:05:27 +00:00
parent 65ee4ccab2
commit ffe587c0a3
2 changed files with 49 additions and 2 deletions

50
ag.cc
View File

@ -58,6 +58,7 @@ namespace ag
// { "sleep", sleep },
{ "startFrame", startFrame },
{ "startList", startList },
{ "type", type },
{ "clearWorld", clearWorld },
/* managed object functions */
@ -78,6 +79,8 @@ namespace ag
luaL_loadstring(L,
"next = ag.next\n"
"type = ag.type\n"
"pairs = function(table)\n"
" return next, table, nil\n"
"end\n"
@ -94,10 +97,10 @@ namespace ag
" return iter_func, table, 0\n"
"end\n"
"ag.createAMotor = function()\n"
"ag.createAMotor = function(obj1, obj2, axis1, axis2, axis3)\n"
"end\n"
);
int s = lua_pcall(L, 0, 0, 0);
lua_pcall(L, 0, 0, 0);
}
static void print_val(lua_State * L, int index)
@ -191,6 +194,49 @@ namespace ag
}
}
int type(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 1)
{
int type = lua_type(L, 1);
switch (type)
{
case LUA_TNUMBER:
lua_pushstring(L, "number");
break;
case LUA_TBOOLEAN:
lua_pushstring(L, "boolean");
break;
case LUA_TSTRING:
lua_pushstring(L, "string");
break;
case LUA_TTABLE:
lua_pushstring(L, "table");
break;
case LUA_TFUNCTION:
lua_pushstring(L, "function");
break;
case LUA_TTHREAD:
lua_pushstring(L, "thread");
break;
case LUA_TUSERDATA:
case LUA_TLIGHTUSERDATA:
lua_pushstring(L, "userdata");
break;
case LUA_TNIL:
default:
lua_pushstring(L, "nil");
break;
}
}
else
{
lua_pushstring(L, "nil");
}
return 1;
}
static void createLuaObject(lua_State * L, int id)
{
lua_newtable(L);

1
ag.h
View File

@ -37,6 +37,7 @@ namespace ag
int sleep(lua_State * L);
int startFrame(lua_State * L);
int startList(lua_State * L);
int type(lua_State * L);
int clearWorld(lua_State * L);
/* 2D overlay functions */