Charl3s7
|
  |
| Joined: 07 Dec 2007 |
| Total Posts: 4146 |
|
|
| 04 Aug 2009 03:36 PM |
Although, an array could be substituted as a struct...
or CLASSES. Lua would be super epic with classes. |
|
|
| Report Abuse |
|
|
| |
|
sncplay42
|
  |
| Joined: 27 Nov 2008 |
| Total Posts: 11891 |
|
| |
|
sncplay42
|
  |
| Joined: 27 Nov 2008 |
| Total Posts: 11891 |
|
|
| 04 Aug 2009 03:38 PM |
| Tables can be used as pass-by-reference structs, and you can use metatables to make tables work like classes anyway. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 04 Aug 2009 03:40 PM |
mystruct = { member1 = "hello", member2 = 3, method1 = function(tb, val) print(tb.member1) end }
mystruct.member1 = 4
mystruct:method1() --> prints 4 |
|
|
| Report Abuse |
|
|
sncplay42
|
  |
| Joined: 27 Nov 2008 |
| Total Posts: 11891 |
|
| |
|
JKM103
|
  |
| Joined: 11 Dec 2008 |
| Total Posts: 1762 |
|
| |
|
Charl3s7
|
  |
| Joined: 07 Dec 2007 |
| Total Posts: 4146 |
|
|
| 04 Aug 2009 07:47 PM |
| Thats what I meant by tables. They can be substituted for structs. But still. Anyone knows how to do that if they know lua. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
| |
|
|
| 04 Aug 2009 08:23 PM |
| Yeah he does. Now i have mai structs in C++ and Lua :D :D :D |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 04 Aug 2009 08:43 PM |
| Isn't a table and an array the same thing, just different languages? |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 05 Aug 2009 10:38 AM |
| tables don't have any order, arrays do... |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
| |
|
|
| 05 Aug 2009 10:41 AM |
Arrays mustn't have any empty values between 1 and it's last non-empty index.
Tables can be sparse. |
|
|
| Report Abuse |
|
|
zac352
|
  |
| Joined: 20 Feb 2009 |
| Total Posts: 4657 |
|
| |
|
|
| 05 Aug 2009 03:52 PM |
| I still dont get metaevents. D: |
|
|
| Report Abuse |
|
|
zac352
|
  |
| Joined: 20 Feb 2009 |
| Total Posts: 4657 |
|
| |
|
sncplay42
|
  |
| Joined: 27 Nov 2008 |
| Total Posts: 11891 |
|
|
| 05 Aug 2009 03:55 PM |
| @objection, zac: Try reading the Lua Reference Manual chapter 2.8. (It's available online.) |
|
|
| Report Abuse |
|
|
| |
|
sncplay42
|
  |
| Joined: 27 Nov 2008 |
| Total Posts: 11891 |
|
|
| 05 Aug 2009 05:31 PM |
| We already have our associated-data grouper. Tables FTW! |
|
|
| Report Abuse |
|
|
Charl3s7
|
  |
| Joined: 07 Dec 2007 |
| Total Posts: 4146 |
|
|
| 05 Aug 2009 09:50 PM |
@*points at first post*
Um, yea I said that you could substitute an array for a struct. -_- |
|
|
| Report Abuse |
|
|
Ozzypig
|
  |
| Joined: 27 Mar 2008 |
| Total Posts: 4906 |
|
|
| 05 Aug 2009 10:30 PM |
| Arrays use numbers and tables use fields (terminology?)? |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2009 08:00 AM |
I'm not very good with terminiology.
With tables you can make all kinds of objects.
Script = {Source = [[print('"Hi")]], Name = "Script1"}
print(Script.Name.." says ") f = coroutine.create(loadstring(Script.Source)) coroutine.resume(f)
--Script builder concept. --Output: Script1 says Hi
|
|
|
| Report Abuse |
|
|
MicroUser
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3601 |
|
| |
|
Charl3s7
|
  |
| Joined: 07 Dec 2007 |
| Total Posts: 4146 |
|
|
| 06 Aug 2009 11:15 PM |
Struct is a part of some languages. Like a class and an array put together.
BUT, those still aren't structs.
Struct example:
struct object{ char* name; }; object milk; milk.name="Milk";
Array:
objects={milk={name="Milk"}}
Thats the only way of doing it in lua. |
|
|
| Report Abuse |
|
|