lua-users home
lua-l archive

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


Chris Marrin wrote:


I did it this way originally and found that the overhead was too high for my app. I am using Lua to interact with a C++ object system, and the Lua userdata is my Lua aspect of a C++ object. That means it gets pushed a lot, so I wanted it to be as efficient as possible. I am using essentially the code above. This is safe for me because the userdata has a metatable with a __gc metamethod. So I know when it is getting collected and can clean up any outstanding references to it.


Same sort of thing here, I'm using a userdata which is just a pointer to a c structure, which is then wrapped in a lua table. Caching a pointer to the userdata on the c side means that the pointer to myself can be nulled from the c side, giving the option of freeing the c side while the lua side is still waiting to be GCd. It also seems the most sensible common point for any interactivity.

All of the data the c side cares about is kept on the c side with function access used on the lua side. The only time I'm coming at it from this direction is to run lua threads associated with the object which need to be triggered by c side activity. Any other time its the lua side accessing the c sides data, which seems to be the way that makes lua happy :) So there isnt really much of an overhead I only do any of this lookup when I'm about to jump into a thread.

I'm only want to run a small active set of these items threads and which ones is up to the c side so I really do need to be able to point at a few and go run that one that one and that one.

--

Kriss

http://XIXs.com -><- http://www.WetGenes.com