From ffe587c0a30caf280fd5443355aaec3e549cbc03 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 28 Jan 2010 05:05:27 +0000 Subject: [PATCH] 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 --- ag.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- ag.h | 1 + 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/ag.cc b/ag.cc index 4d88b40..24fc466 100644 --- a/ag.cc +++ b/ag.cc @@ -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); diff --git a/ag.h b/ag.h index 778f94f..ac63c55 100644 --- a/ag.h +++ b/ag.h @@ -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 */