Inheritance (SWIG/Lua)如何访问SWIG_Lua_类中的基类/父类列表

Inheritance (SWIG/Lua)如何访问SWIG_Lua_类中的基类/父类列表,inheritance,types,lua,parent,swig,Inheritance,Types,Lua,Parent,Swig,我注意到,在为给定的一组类生成的SWIG包装器中,SWIG保留了该类继承的所有父类的C字符串表示的列表。(字符**基本名称)。我知道有一个函数 swig_type(some_variable) 它将返回给定变量数据类型的字符串表示形式。是否还有一个函数可以将父类表作为字符串返回?如果没有,是否有一种简单的方法来编写此函数?我对SWIG的内部工作原理一点也不熟悉 谢谢 类似的东西应该可以工作(未经测试,因为我没有将SWIG与Lua一起使用): 初步测试表明,您的代码工作起来像一个冠军!非常感谢,

我注意到,在为给定的一组类生成的SWIG包装器中,SWIG保留了该类继承的所有父类的C字符串表示的列表。(字符**基本名称)。我知道有一个函数

swig_type(some_variable)
它将返回给定变量数据类型的字符串表示形式。是否还有一个函数可以将父类表作为字符串返回?如果没有,是否有一种简单的方法来编写此函数?我对SWIG的内部工作原理一点也不熟悉


谢谢

类似的东西应该可以工作(未经测试,因为我没有将SWIG与Lua一起使用):


初步测试表明,您的代码工作起来像一个冠军!非常感谢,这是一个很大的帮助!
// insert into runtime section
// this is the C function that iterates over the base_names array 
// (I'm assuming that the array is terminated with a NULL)
%runtime %{
    /* lua callable function to get the userdata's type */
    SWIGRUNTIME int SWIG_Lua_basenames(lua_State* L)
    {
      swig_lua_userdata* usr;
      swig_lua_class* clss = NULL;
      int i = 0;
      if (lua_isuserdata(L,1))
      {
        usr=(swig_lua_userdata*)lua_touserdata(L,1);  /* get data */
        if (usr && usr->type && usr->type->clientdata) {
          // fetch the swig_lua_class struct, it contains the base_names
          clss = (swig_lua_class*)usr->type->clientdata;
        }
      }
      /* create a new table with all class base names in it
         note that I create it even if clss is NULL, that way
         an empty table -should- be returned
       */          
      lua_newtable(L);
      while(clss && clss->base_names[i]) {
         lua_pushnumber(L, i+1); /* lua tables are 1-indexed */
         lua_pushstring(L, clss->base_names[i]);
         lua_rawset(L, -3);
         i++;
      }
      return 1;
    }
%}
%init %{
  /* this goes into the user init function, register our new function with
     Lua runtime
   */
  SWIG_Lua_add_function(L,"swig_base_names",SWIG_Lua_basenames);
%}