LuaBridge3 icon indicating copy to clipboard operation
LuaBridge3 copied to clipboard

How to expose C++ data (a vector, in this case) to Lua without making a copy?

Open totalgee opened this issue 1 year ago • 2 comments

Hi there, I'm learning and experimenting with LuaBridge, and have exposed a test Object class and have created a std::vector<Object> in C++. I want to expose this vector (table) of data to Lua, but without it being a copy. So, for example, if I insert a new entry to the table via Lua (table.insert(test.objs, Object())), I'd like that change to be reflected back in the C++ vector. Likewise, I'd like modifications to the elements of the vector (in C++) to be reflected when accessed later in Lua.

Currently, my attempts to do (including specifying the std::vector<Object> instance as a pointer or reference) this have only resulted in copies of the vector being made available in Lua. (that is to say, a copy is made at the moment of adding the variable to Lua)

Is it even possible to do what I want with LuaBridge? Thanks.

totalgee avatar Mar 17 '24 23:03 totalgee

Refer to this discussion https://github.com/kunitoki/LuaBridge3/discussions/176

kunitoki avatar Mar 18 '24 09:03 kunitoki

Thanks, added a comment there!

totalgee avatar Mar 18 '24 10:03 totalgee