No operators and no constructors for math types #5
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Structs are raw FFI values, so vector math is written as nested calls, comparison is manual, and
building a
Colorneedsffi.newwith a table.Current behavior
Proposal
1. Operators
Install one metatype per value type at the end of the generated file:
Vector2,Vector3,Vector4+ - * / -x == tostringQuaternion+ - * == tostringMatrix+ - * tostring(raymath has no matrix equality)Color== tostring(no arithmetic; raylib colour math is explicit)Details that matter:
*accepts a number on either side:Vector2Scalefor scalars,Vector2Multiplyfor vectors.==usesVector2Equals(a, b) ~= 0, because those functions returnint, notbool.__len:#vmust return an integer, but length returns a float. KeepM.Vector2Length(v).__index: adding methods would make field typos returnnilinstead of erroring.ffi.metatypeis permanent and errors on a second install, so wrap it:2. Constructors
Bad hex strings raise a Lua error, not an FFI abort.
Acceptance criteria
(a + b)equalsM.Vector2Add(a, b); same for*,/,==.tostringoutput is stable and readable.M.Colorforms work; bad input raises a Lua error.make check-bindingspasses.Notes
ffi.new("Vector2", v)still makes an unowned copy; operators never share storage.ergonomic metatypes and operator overloadingto No operators and no constructors for math types