lua-users home
lua-l archive

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


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: pgp7TAaSMY4y7.pgp
Description: PGP signature