objects supported ?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
haringz
Posts: 5
Joined: Mon Oct 24, 2005 5:51 am

objects supported ?

Post by haringz »

Hi,

I just started experimenting with the lua player and I was wondering if objects are supported. Haven't found any code that uses objects.

By objects I mean creating your own objects.

And if not , is it planned , because I don't think you will see any serious game attempts if you can't create objects.

other than that , it rocks :)

I prolly release something soon, and better stuff if I can use objects :)

greeetz
haust
Posts: 25
Joined: Sat Oct 01, 2005 12:37 am
Location: France

Post by haust »

What do you mean by object ?? You mean Object Oriented Program ??
Well Lua support this kind of feature.

Code: Select all

-- -----------------------------------------------------------------------
-- CObject
-- -----------------------------------------------------------------------
CObject = {}
CObjectMetaTable = { __index = CObject }

-- -----------------------------------------------------------------------
-- CObject:new
-- -----------------------------------------------------------------------
function CObject:new() 
	local Table =
	{
		m_TextValue = "TextData",
		m_BoolValue = true,
	}

	setmetatable(Table, CObjectMetaTable);

	return (Table);
end

-- -----------------------------------------------------------------------
-- CObject:doSomething
-- -----------------------------------------------------------------------
function CObject:doSomething()
	if (true == self.m_BoolValue) then
		self.m_TextValue = "OK";
	else
		self.m_TextValue = "CANCEL";
	end
end

-- -----------------------------------------------------------------------
--
-- -----------------------------------------------------------------------
function main()
	local MyObj1 = CObject:new();
	local MyObj2 = CObject:new();

	MyObj1.m_BoolValue = true;
	MyObj2.m_BoolValue = false;

	MyObj1:doSomething();
	MyObj2:doSomething();
end

main();
I don't know for inheritance and other oop stuff but this can be a good start....
haringz
Posts: 5
Joined: Mon Oct 24, 2005 5:51 am

Post by haringz »

thanks mate !

Exactly what I meant.

gonna give it a try tomorrow
Durante
Posts: 65
Joined: Sun Oct 02, 2005 6:07 am
Location: Austria

Post by Durante »

I often say this, but read the book. Especially the chapter on classes. It is a bit dry, but very helpful.
Post Reply