diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-06-19 18:32:22 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-06-19 18:36:21 +0200 |
commit | 64e064330c5c595d0b8553028e0c5ca95c5e5392 (patch) | |
tree | 23607d333632c3b3bfbfee5204ce47db74706f81 /src/lua/tolua_tt.c | |
parent | 2a2fcac0fdb76ce7481ab4ab17e6f64f3ca7bc1d (diff) |
Lua: Remove Lua
Diffstat (limited to 'src/lua/tolua_tt.c')
-rw-r--r-- | src/lua/tolua_tt.c | 316 |
1 files changed, 0 insertions, 316 deletions
diff --git a/src/lua/tolua_tt.c b/src/lua/tolua_tt.c deleted file mode 100644 index 33c384c6..00000000 --- a/src/lua/tolua_tt.c +++ /dev/null @@ -1,316 +0,0 @@ -/* tolua: type & tag manipulation. -** Support code for Lua bindings. -** Written by Waldemar Celes -** TeCGraf/PUC-Rio -** Jul 1998 -** $Id: tolua_tt.c,v 1.2 2001/11/26 23:00:27 darkgod Exp $ -*/ - -/* This code is free software; you can redistribute it and/or modify it. -** The software provided hereunder is on an "as is" basis, and -** the author has no obligation to provide maintenance, support, updates, -** enhancements, or modifications. -*/ - -#include "tolua.h" -#include "tolua_tt.h" -#include "tolua_tm.h" -#include "tolua_eh.h" -#include "tolua_rg.h" - -#include <stdio.h> -#include <string.h> -#include <assert.h> - -/* Global tables created in Lua registry: - tolua_tbl_itype: indexed by instance tags, stores the instance types. - tolua_tbl_itag: indexed by instance types, stores the instance tags. - tolua_tbl_const: indexed by constant tags, stores the tags. - tolua_tbl_hierarchy: indexed by instance tags, stores the base tags. -*/ - -/* exported basic type tags */ -int tolua_tag_nil; -int tolua_tag_number; -int tolua_tag_string; -int tolua_tag_userdata; -int tolua_tag_table; -int tolua_tag_function; - - -static const char* gettype (lua_State* L, int tag) -{ - const char* type; - toluaI_getregistry(L,"tolua_tbl_itype"); - lua_pushnumber(L,tag); - lua_gettable(L,-2); - type = lua_tostring(L,-1); - if (type==NULL) type = "[undefined]"; - lua_pop(L,2); - return type; -} - -const char* toluaI_tt_getobjtype (lua_State* L, int lo) -{ - if (lua_gettop(L)<abs(lo)) - return "[no object]"; - else - return gettype(L,lua_tag(L,lo)); -} - -int toluaI_tt_gettag (lua_State* L, char* type) -{ - int tag; - toluaI_getregistry(L,"tolua_tbl_itag"); - lua_pushstring(L,type); - lua_gettable(L,-2); - tag = (int)lua_tonumber(L,-1); - lua_pop(L,2); - return tag; -} - -static int basetag (lua_State* L, int hierarchy, int tag) -{ - int btag; - lua_pushnumber(L,tag); - lua_gettable(L,hierarchy); - btag = (int)lua_tonumber(L,-1); - lua_pop(L,1); - return btag; -} - -static int istype (lua_State* L, int lo, int tag) -{ - int otag = lua_tag(L,lo); - if (tag==otag) /* check simplest case */ - return 1; - else if (lua_isnil(L,lo) && - tag!=LUA_TNUMBER && - tag!=LUA_TTABLE && - tag!=LUA_TFUNCTION - ) - return 1; - else if ((tag==LUA_TSTRING && lua_isstring(L,lo)) || /* check convertions */ - (tag==LUA_TNUMBER && lua_isnumber(L,lo)) - ) - return 1; - else if (tag==LUA_TUSERDATA && lua_isuserdata(L,lo)) /* pointer to void* */ - return 1; - else if (tag==toluaI_tt_gettag(L,"bool") && otag==LUA_TNUMBER) - return 1; - else - { - /* if requested type is const, the non-const is an alternative type */ - int tag2; - int tbl_hierarchy; - toluaI_getregistry(L,"tolua_tbl_const"); - lua_pushnumber(L,tag); - lua_gettable(L,-2); - tag2 = (int)lua_tonumber(L,-1); - lua_pop(L,2); - if (tag2 && tag2==otag) - return 1; - /* check for base classes */ - toluaI_getregistry(L,"tolua_tbl_hierarchy"); - tbl_hierarchy = lua_gettop(L); - otag = basetag(L,tbl_hierarchy,otag); - while (otag) - { - if (tag==otag || (tag2 && tag2==otag)) - break; - otag = basetag(L,tbl_hierarchy,otag); - } - lua_pop(L,1); - return otag!=0; - } -} - -void toluaI_tt_init (lua_State* L) -{ - lua_newtable(L); toluaI_setregistry(L,"tolua_tbl_itype"); - lua_newtable(L); toluaI_setregistry(L,"tolua_tbl_itag"); - lua_newtable(L); toluaI_setregistry(L,"tolua_tbl_const"); - lua_newtable(L); toluaI_setregistry(L,"tolua_tbl_hierarchy"); - - /* set and register basic Lua type tag */ -#if 0 - lua_pushnumber(L,LUA_TNIL); toluaI_setregistry(L,"tolua_tag_nil"); - lua_pushnumber(L,LUA_TNUMBER); toluaI_setregistry(L,"tolua_tag_number"); - lua_pushnumber(L,LUA_TSTRING); toluaI_setregistry(L,"tolua_tag_string"); - lua_pushnumber(L,LUA_TUSERDATA); toluaI_setregistry(L,"tolua_tag_userdata"); - lua_pushnumber(L,LUA_TTABLE); toluaI_setregistry(L,"tolua_tag_table"); - lua_pushnumber(L,LUA_TFUNCTION); toluaI_setregistry(L,"tolua_tag_function"); - - toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_nil"),"nil"); - toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_number"),"number"); - toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_string"),"string"); - toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_userdata"),"userdata"); - toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_table"),"table"); - toluaI_tt_register(L,toluaI_tt_gettag(L,"tolua_tag_function"),"function"); -#else - toluaI_tt_register(L,LUA_TNIL,"nil"); - toluaI_tt_register(L,LUA_TNUMBER,"number"); - toluaI_tt_register(L,LUA_TSTRING,"string"); - toluaI_tt_register(L,LUA_TUSERDATA,"userdata"); - toluaI_tt_register(L,LUA_TTABLE,"table"); - toluaI_tt_register(L,LUA_TFUNCTION,"function"); - toluaI_tt_register(L,lua_newtag(L),"bool"); -#endif -} - - -void toluaI_tt_register (lua_State* L, int tag, char* type) -{ - toluaI_getregistry(L,"tolua_tbl_itype"); - lua_pushnumber(L,tag); - lua_pushstring(L,type); - lua_settable(L,-3); - - toluaI_getregistry(L,"tolua_tbl_itag"); - lua_pushstring(L,type); - lua_pushnumber(L,tag); - lua_settable(L,-3); - - lua_pop(L,2); -} - - -void toluaI_tt_class (lua_State* L, int lo, char* derived, char* base) -{ - char* cderived = toluaI_tt_concat("const ",derived); - int tag = toluaI_tt_gettag(L,derived); - int ctag = toluaI_tt_gettag(L,cderived); - toluaI_tm_instance(L,tag,lo); - toluaI_tm_instance(L,ctag,lo); - if (*base != 0) - { - char* cbase = toluaI_tt_concat("const ",base); - int btag = toluaI_tt_gettag(L,base); - int cbtag = toluaI_tt_gettag(L,cbase); - toluaI_tt_sethierarchy(L,tag,btag); - toluaI_tt_sethierarchy(L,ctag,cbtag); - } -} - -void toluaI_tt_sethierarchy (lua_State* L, int tag, int btag) -{ - toluaI_getregistry(L,"tolua_tbl_hierarchy"); - lua_pushnumber(L,tag); - lua_pushnumber(L,btag); - lua_settable(L,-3); - lua_pop(L,1); -} - -char* toluaI_tt_concat (const char* s1, const char* s2) -{ - static char s[BUFSIZ]; - assert(strlen(s1)+strlen(s2)<BUFSIZ); - return strcat(strcpy(s,s1),s2); -} - -void tolua_usertype (lua_State* L, char* type) -{ - /* check if type is already registered */ - toluaI_getregistry(L,"tolua_tbl_itag"); - lua_pushstring(L,type); - lua_gettable(L,-2); - if (lua_isnil(L,-1)) - { - char *ctype = toluaI_tt_concat("const ",type); - int tag = lua_newtag(L); - int ctag = lua_newtag(L); - toluaI_tt_register(L,tag,type); - toluaI_tt_register(L,ctag,ctype); - /* set const table */ - toluaI_getregistry(L,"tolua_tbl_const"); - lua_pushnumber(L,ctag); - lua_pushnumber(L,tag); - lua_settable(L,-3); - lua_pop(L,1); - } - lua_pop(L,2); -} - -int toluaI_tt_isusertype (lua_State* L, int lo) -{ - if (lua_isuserdata(L,lo) && - toluaI_tt_gettag(L,"tolua_tag_userdata")!=lua_tag(L,lo) - ) - { - int status; - toluaI_getregistry(L,"tolua_tbl_itype"); - lua_pushnumber(L,lua_tag(L,lo)); - lua_gettable(L,-2); - status = !lua_isnil(L,-1); - lua_pop(L,2); - return status; - } - return 0; -} - -#if 0 -void tolua_settag (lua_State* L, char* type, int* tag) -{ - toluaI_getregistry(L,"tolua_tbl_itag"); - lua_pushstring(L,type); - lua_gettable(L,-2); - *tag = (int) lua_tonumber(L,-1); - lua_pop(L,2); -} -#endif - -int tolua_istype (lua_State* L, int narg, int tag, int def) -{ - if (lua_gettop(L)<abs(narg)) - { - if (def==0) - { - toluaI_eh_set(L,narg,toluaI_tt_getobjtype(L,narg),gettype(L,tag)); - return 0; - } - } - else - { - if (!istype(L,narg,tag)) - { - toluaI_eh_set(L,narg,toluaI_tt_getobjtype(L,narg),gettype(L,tag)); - return 0; - } - } - return 1; -} - -int tolua_arrayistype (lua_State* L, int narg, int tag, int dim, int def) -{ - int i; - for (i=0; i<dim; ++i) - { - int tf; - lua_pushnumber(L,i+1); - lua_gettable(L,narg); - tf = lua_gettop(L); - if (!istype(L,tf,tag) && (!def || !lua_isnil(L,tf))) - { - static char t1[BUFSIZ], t2[BUFSIZ]; - sprintf(t1,"array of %s",toluaI_tt_getobjtype(L,tf)); - sprintf(t2,"array of %s (dimension=%d)",gettype(L,tag),dim); - toluaI_eh_set(L,narg,t1,t2); - return 0; - } - lua_pop(L,1); - } - return 1; -} - -int tolua_isnoobj (lua_State* L, int narg) -{ - if (lua_gettop(L)>=abs(narg)) - { - toluaI_eh_set(L,narg,toluaI_tt_getobjtype(L,narg), - toluaI_tt_getobjtype(L,lua_gettop(L)+1)); - return 0; - } - return 1; -} - - |