Help on using Luna(or Lunar)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Help on using Luna(or Lunar)

jose marin2
Hi!

I have a problem when using Luna (or Lunar):

How I create a method to deal with this:

a = Account(100)
b = Account(200)

b:check(a)


The problem is how to, inside the method 'check', get
the pointer to the class Account.




	
	
		
Yahoo! Acesso Grátis - Internet rápida e grátis. 
Instale o discador agora! http://br.acesso.yahoo.com/

Reply | Threaded
Open this post in threaded view
|

Re: Help on using Luna(or Lunar)

Fabian Peña
Jose Marin wrote:

Hi!

I have a problem when using Luna (or Lunar):

How I create a method to deal with this:

a = Account(100)
b = Account(200)

b:check(a)


The problem is how to, inside the method 'check', get
the pointer to the class Account.




	
	
		
Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora! http://br.acesso.yahoo.com/

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);
	...
... ...
}



Reply | Threaded
Open this post in threaded view
|

Re: Help on using Luna(or Lunar)

jose marin2
In reply to this post by jose marin2
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/

Reply | Threaded
Open this post in threaded view
|

Re: Help on using Luna(or Lunar)

Groleo Marius
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
<[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

Re: Help on using Luna(or Lunar)

jose marin2
In reply to this post by jose marin2
It worked!

Thank you very much!

--- Groleo Marius <[hidden email]> wrote:
> 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
>      }



	
	
		
Yahoo! Acesso Grátis - Internet rápida e grátis. 
Instale o discador agora! http://br.acesso.yahoo.com/