Question about native vector math #813
-
I have been looking for an embeddable scripting language where I don't have to jump thru hoops to avoid many tiny heap allocations and garbage collection pauses for simple vector math. I built Luau on Mac from source and have been playing with the REPL. I saw that Luau supports native vectors from this section in the docs: https://luau-lang.org/performance#native-vector-math This is really fantastic and one of the big sells of Luau in my opinion; amazing work! But one thing's not clear to me --- does the runtime perform this optimization automatically for any table that contains 3 floats? It seems
But this implies that the runtime won't make use of type annotations to make assumptions about how to represent data:
So, I'm clearly missing something, such the syntax for a vector primitive literal. Is this optimization only available through the Roblox API? Thanks for any help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Runtime doesn't detect this type automatically. For example, when you have created a VM, you register a function to build a vector:
Optionally, in compilation options, you can specify:
This will tell the compiler that when it sees a To get methods and custom properties to wok on vector values, set a single metatable for vector type. |
Beta Was this translation helpful? Give feedback.
Runtime doesn't detect this type automatically.
Instead, you need to provide a constructor function that returns the vector value.
For example, when you have created a VM, you register a function to build a vector:
Optionally, in compilation options, you can specify:
This will tell the co…