1

How to call a nested function from string?

function first()
    function nested() print('function: nested') end
    print('function: first')
end

_G["first"]() --Calls first function from string

1 Answer 1

1

nested is a global variable, so you can call it with nested() or _G.nested() or _G["nested"]().

Sign up to request clarification or add additional context in comments.

2 Comments

thx, but that's not working for me. It throws "attempt to call a nil value (field 'nested')"
nested is only defined after first is called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.