Lua objects as arguments

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

Lua objects as arguments

Post 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.
MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

Re: Lua objects as arguments

Post by MrPickle »

Ahh, I've found out how.

You pass them like any other variable!
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot] and 8 guests