Maybe have pointer in lua?

I will keep it simple.
Is there a Pointer in lua?
What is Pointer? It is a way of referring to the place where something is stored (a memory area).
C++ ex:

int num= 10;
int *pointer= #

I don’t think there are any “pointers”, but you can always print out your variables to get the memory address of the variable:

local a = {}
print(a) -- table: 0x4298bf6a50d94d6a

This is what i want!
And table, function is an alternative that I used to use. But it’s actually a bit wordy!

1 Like

Tables and any objects are always passed by reference, but there’s no pointers.

1 Like

I think lua really doesn’t have one. But we can replace it with function.
pointer

local _pointer
local function pointer(value)
	if value then
		_pointer= value
	else
		return _pointer
	end
end

This is the same for get, set in C#

How it linked with pointers? It just checks if value isn’t null and if true - return argument u passed. In a nutshell: “value = value”. No logic

Ah I looked more into it and only userdata has it.

1 Like