lua-users home
lua-l archive

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


Looks like methods work now, but I have another problem. When I use
"user:GetNick()" in Lua, it segfaults.

All I get are pointers to users, and I create the userdata with:

struct user *llua_pushuser (lua_State *L, struct user *user_ptr) {
  struct user *l_user = (struct user*)lua_newuserdata(L, sizeof(struct user*));
  l_user = user_ptr;
  luaL_getmetatable(L, TYPE);
  lua_setmetatable(L, -2);
  return l_user;
}

Now when I use "PrintUserInfo(llua_checkuser(L, 1))" in the GetNick C
function it segfaults:

PrintUserInfo: 0x8158a4c
 -> nick:
 -> numeric: ¸hï·
 -> oper: 96
Segmentation fault

Here's my "llua_checkuser" function:

struct user *llua_checkuser (lua_State *L, int index) {
  struct user *user_ptr;
  luaL_checktype(L, index, LUA_TUSERDATA);
  user_ptr = (struct user*)luaL_checkudata(L, index, TYPE);
  if (user_ptr == NULL) luaL_typerror(L, index, TYPE);
  return user_ptr;
}

I think 0x8158a4c points to something inside Lua, and not the user
pointer... I hope I make sense. Is there anything I'm doing wrong
here?

Anders

On 4/12/06, jdarling@eonclash.com <jdarling@eonclash.com> wrote:
> > TYPE is defined as "L2.user".
>
> Unless something has changed you can't use dot notation in your libarary
> or variable names.
>
> I use __index and __newindex to "catch" object properties __index is
> read (or get) and __newindex is write (or set).  Instead they should be
> set to the meta-table (as your doing).  My guess (and at this point its
> only a guess) is that the dot notation in your table name is throwing
> things off.  Try "L2_user" instead of "L2.user" and see what happens.
>
> >
> > The GD binding example code works in 5.1 (the methods work), but they
> > don't in my code so there must be something I'm doing differently...
> > but what? Reading your Delphi code didn't really help me (I don't have
> > a C function for __index, and I couldn't exactly figure out what to do
> > instead). Should I open the library in a certain way?
> >
> > Anders
>
>
>