-
Hey! 👋 I'm trying to come up with a scripting API for an application, and The thing is, I need a way to expose simple So it looks like the userdata solution incurs too much overhead, but I'm not aware of any other mechanism to do something like this. So I'd like to ask if there's something a bit more lightweight than userdata in |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You could implement |
Beta Was this translation helpful? Give feedback.
-
After some benchmarking of this solution, it looks like the table creation overhead is comparable to the overhead of creating a new userdata. But once the vectors are in Lua, as tables, the more computations that are made in Lua code, the more the vector math is optimized by runtimes like LuaJit, whereas userdata will take the same performance hit on every vector operation. So indeed, it looks like tables with metamethods ended up being better :) |
Beta Was this translation helpful? Give feedback.
You could implement
ToLua
andFromLua
traits for your type and store a struct holding N floats in a lua table (with overloaded operators via metatable).