Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:25:27+00:00 2026-06-02T08:25:27+00:00

A simple question: How do I set the prototype for a function that has

  • 0

A simple question: How do I set the prototype for a function that has not been implemented yet?

I just want to do this, cause I’m referring to a function that does not exist(yet).
In C, we would do something like this:

int foo(int bar);

int myint = foo(1);

int foo(int bar)
{
     return bar;
}

How do I do this in Lua (with corona)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:25:30+00:00Added an answer on June 2, 2026 at 8:25 am

    You can’t. Amber’s comment is correct.

    Lua doesn’t have a concept of type signatures or function prototypes.

    The type of foo is that of the object it contains, which is dynamic, changing at runtime. It could be function in one instant, and string or integer or something else in the next.

    Conceptually Lua doesn’t have a compilation step like C. When you say “run this code” it starts starts executing instructions at the top and works it’s way down. In practice, Lua first compiles your code into bytecode before executing it, but the compiler won’t balk at something like this:

    greet()
    
    function greet()
        print('Hello.')
    end
    

    Because the value contained in greet is determined at runtime. It’s only when you actually try to call (i.e. invoke like a function) the value in greet, at runtime, that Lua will discover that it doesn’t contain a callable value (a function or a table/userdata with a metatable containing a __call member) and you’ll get a runtime error: “attempt to call global ‘greet’ (a nil value)”. Where “nil value” is whatever value greet contained at the time the call was attempted. In our case, it was nil.

    So you will have to make sure that that the code that creates a function and assigns it to foo is called before you attempt to call foo.


    It might help if you recognize that this:

    local myint = foo(1)
    
    function foo(bar)
         return bar
    end
    

    Is syntax sugar for this:

    local myint = foo(1)
    
    foo = function(bar)
         return bar
    end
    

    foo is being assigned a function value. That has to happen before you attempt to call that function.


    The most common solution to this problem is to treat the file’s function as the “compilation time”, that is: declare all of your constant data and functions when the file is executed, ready to be used during “execution time”. Then, call a main function to begin the “execution time”.

    For example:

    function main()
        greet()
    end
    
    function greet()
        print('Hello.')
    end
    
    main()
    

    As greet has been declared in _G, main can access it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question, I just want to select the text from the <Template> tag. Here's
This has been an age old question and I am aware of the usual
Simple question this time, is there a way in ASP.NET to set a decimal
This is a simple question. does anyone know how to set up a date
Simple question.. just can't get the result set in the order I need :p
Simple question I hope. If I have a set of data like this: Classification
I am learning WPF and have this simple question. How do I set fill
simple question.. how do I set a redirect if the user selects not allow
This is seems like a pretty simple question. Is it possible to set a
I'm just trying to figure out a probably simple question. Should views set model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.