C Struct new instance

The Struct object allows you to define a C struct. To create a new C struct instance from this definition, simply call this object with or without initialization values.

Notes

To initialize Struct fields, you can provide as arguments :
  • A table that contains the fields with the corresponding values.
  • Or a succession of values that will be affected in order to the Struct fields.
  • Any Value, Struct, Union or [ ] Array.
  • If no initialization value is provided, all struct fields are set to 0 or NULL

Example

local c = require "c" -- Defines a RECT Struct definition local RECT = c.Struct("iiii", "left", "top", "right", "bottom") -- Creates a new RECT instance with table initialization local rect1 = RECT { top = 110, left = 140, right = 200, bottom = 320 } -- Creates a new RECT instance with arguments initalization local rect2 = RECT(140, 110, 200, 320) -- Creates a new RECT instance without initialization local rect3 = RECT() print(rect1.left) -- prints 140 print(rect2.left) -- prints 140 print(rect3.left) -- prints 0