lua-users home
lua-l archive

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


Hope this helps.
Note that when you declare something like:
 a =Account(100);
a is already a pointer to the class Account.

I presume this is what you are looking for:
If i'm wrong, please be more specific.


 static int check( lua_State *L) {
          Account* a =checkAccount( L, 1);
          int amount =( int)luaL_checknumber( L,2 );
          a->check( amount);
          return 0; // supose Account::check doesent return any value
     }
     
static Account* checkAccount( lua_State* L, int narg) {
          luaL_checktype( L, narg, LUA_TUSERDATA);
          void* ud =luaL_checkudata( L, narg, className);
          if( ! ud)
               luaL_typerror( L, narg, className);
          return *( Wrapper**) ud;                 // unbox pointer
     }



On Mon, 28 Mar 2005 18:03:48 -0300 (ART), Jose Marin
<jose_marin2@yahoo.com.br> wrote:
> Thanks, Fabian, but I'm using version 5.0.2 , and the
> code doesn't worked (crashed!)!
> 
> > this code is valid for luna template for lua 4.x (I
> > think)
> >
> > int your_class::check(lua_State *L)
> > {
> >       your_class *p;
> >       lua_pushnumber(L, 0); /* userdata object is stored
> > in index 0 */
> >       lua_gettable(L, 1);             /* first argument for the user
> > function y the table object
> >       p = (some_class *)lua_touserdata(L,-1);
> >       lua_pop(L,1);
> >       ...
> 
> Yahoo! Acesso Grátis - Internet rápida e grátis.
> Instale o discador agora! http://br.acesso.yahoo.com/
> 


-- 
Regards, Groleo!

# touch universe
# chmod +rwx universe
# ./universe