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

  • Home
  • SEARCH
  • 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 823965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:01:40+00:00 2026-05-15T03:01:40+00:00

Supposed I register many different function names in Lua to the same function in

  • 0

Supposed I register many different function names in Lua to the same function in C. Now, everytime my C function is called, is there a way to determine which function name was invoked?

for example:

int runCommand(lua_State *lua)
{
  const char *name = // getFunctionName(lua) ? how would I do this part
  for(int i = 0; i < functions.size; i++)
    if(functions[i].name == name)
      functions[i].Call()
}

int main()
{
  ...

  lua_register(lua, "delay", runCommand);
  lua_register(lua, "execute", runCommand);
  lua_register(lua, "loadPlugin", runCommand);
  lua_register(lua, "loadModule", runCommand);
  lua_register(lua, "delay", runCommand);
}

So, how do I get the name of what ever function called it?

  • 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-05-15T03:01:41+00:00Added an answer on May 15, 2026 at 3:01 am

    Another way to attack your question is by using upvalues. Basically, you register the C functions with the function below instead of lua_register:

    void my_lua_register(lua_State *L, const char *name, lua_CFunction f)
    {
          lua_pushstring(L, name);
          lua_pushcclosure(L, f, 1);
          lua_setglobal(L, name);
    }
    

    Then, getFunctionName is straight forward

    const char* getFunctionName(lua_State* L)
    {
        return lua_tostring(L, lua_upvalueindex(1));
    }
    

    That said, what you trying to do seems fishy – what are you trying to achieve? The runCommand function posted in the question looks like a horribly inefficient way to do something that Lua does for you anyway.

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

Sidebar

Ask A Question

Stats

  • Questions 494k
  • Answers 494k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Unfortunately, you can't figure out the type due to erasure… May 16, 2026 at 11:05 am
  • Editorial Team
    Editorial Team added an answer You already mentioned one possible solution, which is to use… May 16, 2026 at 11:05 am
  • Editorial Team
    Editorial Team added an answer Without the complete code I can't see exactly what would… May 16, 2026 at 11:05 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

There is something I can't digest. I'm learning some assembler and right now I'm
I have a loading overlay which is supposed to block all the AppKit Controls
The program is supposed to accept telnet connections on port 8888 and then send
In C, I can allocate a register for a variable, for example: register int
I'm making a form for user registration. Here's what my template looks like: <h1>Register</h1>
I'm trying to populate a second dropdown in a dynamic way based on a
A picture is supposed to be worth a 1000 words, so let's see if
I'm writing a program for a school project that is supposed to emulate the
I'm in the settings.py module, and I'm supposed to add the directory to the
Short question. I just got a dll I'm supposed to interface with. Dll uses

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.