Skip to content

How to declare record functions on a nested record #648

Closed Answered by Andre-LA
Andre-LA asked this question in Q&A
Discussion options

You must be logged in to vote

Making a correction here, the above method (by aliasing) doesn't works with nested records (with more depth than 1) and don't seems to be the apropriate way of declaring functions either.

The following way, described by the tutorial, it's reliable and works in any nesting level:

If you want to define the function in a later scope (for example, if it is a callback to be defined by users of a module you are creating), you can declare the type of the function field in the record and fill it later from anywhere:

local record Obj
   location: Point
   draw: function(Obj)
end

Closing.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Andre-LA
Comment options

You must be logged in to vote
1 reply
@Andre-LA
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants