lua-users home
lua-l archive

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


All -
I have created a C++ wrapper class for the lua_userdata functionality, rooted in the 'gettable' tag method. I think it will be very useful, since it reduces the calls needed to set up a userdata method from many to 2.

An example of the usage:

   class GeneralData : public LuaUserData<GeneralData> {
   public:
      int Spin(lua_State *) { printf("Spinning\n"); return 0; }
      void RegisterMethods(void)
      { RegisterLuaMethod("Spin", GeneralData, Spin); }
   };

   ...

   lua_State *interp = lua_open(0);
   lua_baselibopen(interp);

   GeneralData myData;
   // Initialize it with the optional parameter of a global variable
   // to set to the userdata.
   myData.InitializeLua(interp, "myData");
   lua_dostring(interp, "myData:Spin();");

The full source code is located at:
http://www.rm-f.net/~gambit/lua/

I welcome any comments :)
--G

We can rebuild it.  We have the technology.