1

p={update=function(} print("hello") end}

I can call the function within p using p.update() outside the table.

How do I call unnamed functions though? i.e.

p={function(} print("hello") end}

If I know the index of the function, 1 in this case, can I use that in my function call? like p1? I've tried some variations of this to no success.

1 Answer 1

3

Yes. p.update is just syntactic sugar for one-word string keys.

The more general way to index a table is to put the key value in brackets:

p[1]()
Sign up to request clarification or add additional context in comments.

1 Comment

okay, not sure what mistake I was making before but its working with the above now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.