Quick question, learning C++ and just learned about what references can do. Was wondering if Lua has something like that, because I was looking for something like it.
i.g. C++
Code: Select all
int add(int& num1, int num2){
num1 += num2
return num1
}
void main(){
int x = 10
add(x, 5)
std::cout << x << std::endl;
}
Output: 15
or to put it more directly for what I want it...
Code: Select all
Banana = "fruit"
pantry = {}
pantry.orange = banana --believe it or not, logic does apply here
function rotfood()
pantry.orange = "rotten"
end
But I was the Banana to rot too without directly referencing the banana. I'd like it to be this way... Transfer variable1 to variable2. When variable2 changes, I want variable1 to change. any linking of variables?I'm just trying not to have to more lines of code to transfer the variable1 to variable2 and then from variable2 back to variable1. Possible in Lua?
EDIT:
I'm sorry, that C++ thing doesn't even do that. But I'm still learning. Is there still anyway to accomplish what I explained in the above paragraph?