lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


One approach I use is set an environment on the userdata when it is created.  I use this table to store any properties or methods associated with the object.  In the __index metamethod, I also allow rollover into the klass' metatable:

  int indexMetaMethod( lua_State *L )
  {
      lua_getfenv( L, 1 );
      lua_pushvalue( L, 2 );
      lua_rawget( L, -2 );

      if (!lua_isnil( L, -1 ))
        return 1;

      /* get the field from the object's klass table */
      lua_pop( L, 2 );

      lua_getmetatable( L, 1 );
      lua_pushvalue( L, 2 );
      lua_rawget( L, -2 );

      if (!lua_isnil( L, -1 ))
        return 1;

      return 0;
   }


_______________________________________________
No banners. No pop-ups. No kidding.
Make My Way  your home on the Web - http://www.myway.com