| View previous topic :: View next topic |
| Author |
Message |
haringz
Joined: 24 Oct 2005 Posts: 5
|
Posted: Mon Oct 24, 2005 5:58 am Post subject: objects supported ? |
|
|
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 |
|
| Back to top |
|
 |
haust
Joined: 01 Oct 2005 Posts: 25 Location: France
|
Posted: Mon Oct 24, 2005 7:06 am Post subject: |
|
|
What do you mean by object ?? You mean Object Oriented Program ??
Well Lua support this kind of feature.
| Code: | -- -----------------------------------------------------------------------
-- 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.... |
|
| Back to top |
|
 |
haringz
Joined: 24 Oct 2005 Posts: 5
|
Posted: Mon Oct 24, 2005 8:23 am Post subject: |
|
|
thanks mate !
Exactly what I meant.
gonna give it a try tomorrow |
|
| Back to top |
|
 |
Durante
Joined: 02 Oct 2005 Posts: 65 Location: Austria
|
Posted: Mon Oct 24, 2005 8:34 am Post subject: |
|
|
| I often say this, but read the book. Especially the chapter on classes. It is a bit dry, but very helpful. |
|
| Back to top |
|
 |
|