Page 1 of 1

Lua objects as arguments

Posted: Fri Jul 11, 2008 6:42 pm
by MrPickle
How do you pass an object from one function into another?

Here is my basic object:

Code: Select all

-- Very basic position object for now
Position = {}
Position_mt = {}

function Position:new(Temp_x, Temp_y)
	Temp_x = Temp_x or 0
	Temp_y = Temp_y or 0
	
	newPosition = { x = Temp_x, y = Temp_y }
	return setmetatable(newPosition, Position_mt)
end

Position_mt.__index = Position
I would like to pass one "Position" from one function into another but I am not sure as to how you do it?

Sorry, I am new to Lua.

Re: Lua objects as arguments

Posted: Fri Jul 11, 2008 8:18 pm
by MrPickle
Ahh, I've found out how.

You pass them like any other variable!