Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a table from C++ to Lua #75

Open
ehrhart opened this issue Sep 17, 2014 · 3 comments
Open

Passing a table from C++ to Lua #75

ehrhart opened this issue Sep 17, 2014 · 3 comments

Comments

@ehrhart
Copy link
Contributor

ehrhart commented Sep 17, 2014

Hello,

Is there currently any way to create a table in C++ and pass it to a Lua function?

I'm actually trying to convert a std::vector (or a std::list) so I can pass it to my Lua function

Thanks

@Tomasu
Copy link
Owner

Tomasu commented Sep 18, 2014

Hmm. There is no api currently to take a container and convert it to a lua table.

I've thought about this a little, and i can go two ways.. Either just auto-wrap std containers directly, or have stack functions automatically take the container and turn it into a table...

Wrapping the containers would make it so you can actually change the container directly in lua, not wrapping would mean you can't change the container, but it might be faster to access the data in lua because it doesn't have to bother with metatables and metamethods.

@ehrhart
Copy link
Contributor Author

ehrhart commented Sep 18, 2014

Both ways are interesting, the latter one would work with my case.
You could also have a LuaTable wrapper where you can put() basic variables or shared_ptrs

@ehrhart ehrhart closed this as completed Sep 18, 2014
@ehrhart ehrhart reopened this Sep 18, 2014
@Tomasu
Copy link
Owner

Tomasu commented Sep 18, 2014

Both ways are more or less equivalent if all you want to do is pass a stl container into lua as a table. The first would be implemented as a userdata object implementing the __(new)index metamethods. The second would just create a table and populate it with the items from the stl container.

As for a lua table wrapper, there is already a class (LuaGlueLuaTable) that could be extended to support that. And I might at some point. Right now it only exists to support passing tables back into C++ from lua.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants