How to create efficient bindings from Go slices/arrays/maps to Lua tables #487
ChrisTrenkamp
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm writing a Go source code generator for binding Go struct fields/methods to GopherLua:
https://github.com/ChrisTrenkamp/lua-userdata-generator
It can generate source code for primitive's, struct's, and interface's (provided the interface has a certain method for getting the metatable name). Now I'm looking to create bindings for slices/arrays/maps.
I'm not sure how to do this. I want to create bindings that are as efficient as possible. It should avoid as much copying as possible while trying to preserve Lua's semantics for table operations.
I thought about wrapping the slices/maps with a struct with methods for modifying/retrieving data from the field, but this wouldn't preserve the semantics for operating on tables in Lua. Instead of writing table index operations, you'd be calling methods.
On the other hand, it could copy the slice/map information into a new Lua table, but that would be really inefficient.
Does anyone have some pointers for getting started? Is there a happy medium that can be achieved for binding slices/maps to Lua?
Beta Was this translation helpful? Give feedback.
All reactions