lua-users home
lua-l archive

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


Hi,

Mike Crowe wrote:
Hi folks,

Has anybody linked c++ programs with 5.1 and lunar.h before? I've gotten my program to compile with lunar.h with a few tweaks, but I don't know if there are hidden gotcha's to be aware of.

[snip code]

it all seems to work.

Mainly, I'm worried that this example doesn't use all the features of lunar.h, and when we dive into it, we get bit by something we don't anticipate.


I used luna(r).

- I didn't find a way to access class' member fields directly (or add new members to it in script).
- I added a get method (modified from check):

  static T *get(lua_State *L, int narg) {
    userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, narg));
    if(!ud) return NULL;
    return ud->pT;  // pointer to T object
  }

I used this for something like:

class A {};
class AA : public A {};
class AB : public A {};
Luna<AA>::Register(L);
Luna<AB>::Register(L);

X* get_obj(lua_State* L) {
  A* o=NULL;
  o = Luna<AA>::get(L, 1);
  if (o) return o->x;
  o = Luna<AB>::get(L, 1);
  if (o) return o->x;
  luaL_argcheck(L, o != NULL, 1, "'...' expected");
}


TIA

Mike



--
Regards,
Hakki Dogusan