lua-users home
lua-l archive

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


Okay. I've managed to figure out tags as they pertain to userdata, and
rewrote my API to set and check the tags of any userdata objects it uses.
And guess what? The tags match, which means my problem must not be the wrong
variables being passed. The important code looks like this now:

console_write("This is the beginning...\n")
viewport_translaterd(self.viewport, self.pitch, self.yaw, self.roll,
self.velocity * ticks_per_frame)
console_wirte("This is the end.\n")

cosole_write() looks like this:

int api_console_write(lua_State *client_state)
{
 // console_write(string text)

 if (lua_gettop(client_state))
  cerr << lua_tostring(client_state, 1);

 return 0;
}

and viewport_translaterd() looks like this:

int api_viewport_translaterd(lua_State *client_state) // Relatively
translate a viewport directionally
{
 // viewport_translaterd(userdata viewport_pointer, number pitch, number
yaw, number roll, number distance)

 if ((lua_gettop(client_state) >= 5) && (lua_tag(client_state, 1) ==
Viewport_tag))
 {
  Viewport *this_viewport = (Viewport *) lua_touserdata(client_state, 1);
  int distance = (int) lua_tonumber(client_state, 5);

  cerr << "The tag of the first argument to viewport_translaterd() is " <<
lua_tag2name(client_state, lua_tag(client_state, 1)) << '\n';

  // Must use trig to find x/y/z values
  this_viewport->camera_x += sin_lookup[(int) lua_tonumber(client_state, 3)]
* distance; // sin yaw * distance
  this_viewport->camera_y += sin_lookup[(int) lua_tonumber(client_state, 4)]
* distance; // sin roll * distance
  this_viewport->camera_z += sin_lookup[(int) lua_tonumber(client_state, 2)]
* distance; // sin pitch * distance
 }

 return 0;
}

Now, it still segfaults right after doing that cerr output. But, if I
comment out the line in the lua code that calls viewport_translaterd(),

console_write("This is the beginning...\n")
-- viewport_translaterd(self.viewport, self.pitch, self.yaw, self.roll,
self.velocity * ticks_per_frame)
console_wirte("This is the end.\n")

it still segfaults after the first console_write(), without the cerr output
from viewport_translaterd()! Now how do you figure that...

Thanks, Philip Bock