[Date Prev][Date Next][Thread Prev][Thread Next]
- 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
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
userdata* u = createuserdata()
*u = ptr;
*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
| firstname.lastname@example.org | coming to a middle." --- Firefly, _Our Mrs.
| (email@example.com) | Reynolds_
+- www.cowlark.com --+
Description: PGP signature