[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: NILifiying user variables
- From: David Given <dg@...>
- Date: Wed, 8 Feb 2006 12:49:34 +0000
On Wednesday 08 February 2006 12:34, LEGO wrote:
[...]
> This variables are accessed very often while analyzing packets so
> having to either copy them or create and destroy a container that
> keeps track o the frame number they come from would sensibly slow down
> operation.
Ha!
I have *exactly* this issue with something I'm doing. My solution is to zap
the content of the userdata to make the variable unusable one the callback
has returned.
callback(void* ptr)
{
userdata* u = createuserdata()
*u = ptr;
...call lua...
*u = NULL;
}
My Lua bindings for accessing the underlying structure then have to check to
ensure that the userdata is valid before dereferencing it. If it's not valid,
it call luaL_error().
This should ensure that if anyone keeps one of these structures longer than
they're supposed to, it should have no harmful effects (other than causing
their code to break, which it would anyway). Does this approach work for you?
--
+- David Given --McQ-+ "My days of taking you seriously are certainly
| dg@cowlark.com | coming to a middle." --- Firefly, _Our Mrs.
| (dg@tao-group.com) | Reynolds_
+- www.cowlark.com --+
Attachment:
pgp2BTIUh4xfe.pgp
Description: PGP signature