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 7077847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:28:25+00:00 2026-05-28T06:28:25+00:00

I have the following code in Lua: ABC: test (X) The test function is

  • 0

I have the following code in Lua:
ABC:

test (X)

The test function is implemented in C + +. My problem is this: I need to know what the variable name passed as parameter (in this case X). In C + + only have access to the value of this variable, but I must know her name.

Help please

  • 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-28T06:28:26+00:00Added an answer on May 28, 2026 at 6:28 am

    Functions are not passed variables; they are passed values. Variables are just locations that store values.

    When you say X somewhere in your Lua code, that means to get the value from the variable X (note: it’s actually more complicated than that, but I won’t get into that here).

    So when you say test(X), you’re saying, “Get the value from the variable X and pass that value as the first parameter to the function test.”

    What it seems like you want to do is change the contents of X, right? You want to have the test function modify X in some way. Well, you can’t really do that directly in Lua. Nor should you.

    See, in Lua, you can return values from functions. And you can return multiple values. Even from C++ code, you can return multiple values. So whatever it is you wanted to store in X can just be returned:

    X = test(X)
    

    This way, the caller of the function decides what to do with the value, not the function itself. If the caller wants to modify the variable, that’s fine. If the caller wants to stick it somewhere else, that’s also fine. Your function should not care one way or the other.

    Also, this allows the user to do things like test(5). Here, there is no variable; you just pass a value directly. That’s one reason why functions cannot modify the “variable” that is passed; because it doesn’t have to be a variable. Only values are passed, so the user could simply pass a literal value rather than one stored in a variable.

    In short: you can’t do it, and you shouldn’t want to.

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

Sidebar

Related Questions

I have following code in a html form <select name=category class=input onchange=ShowTB(this,'suggest');> <option value=0
I have following code class User attr_accessor :name end u = User.new u.name =
How do I extract files using Lua? Update: I now have the following code
Currently I know how to have C++ objects instantiated and passed around in Lua
I have the following code: function collisionDetect(left1,right1,top1,bottom1,left2,right2,top2,bottom2,dir) local left,right,top,bottom=false,false,false,false if left1<right2 then left=true end
This is a really specific compilation problem involving C++, SWIG and Lua. I have
I have following code for alertdialog: AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this); helpBuilder.setTitle(Options); helpBuilder.setMessage(Choose Your
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have following code in my application: // to set tip - photo in

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.