Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex example #48

Open
rbukovansky opened this issue Jun 18, 2018 · 5 comments
Open

Complex example #48

rbukovansky opened this issue Jun 18, 2018 · 5 comments

Comments

@rbukovansky
Copy link

rbukovansky commented Jun 18, 2018

Hi, I just love your framework (finally I don't see myself lost coming from C# and Swift worlds), but is there any complex example? I'm currently looking for these:
1] How do you create collections of class objects?
2] How to have class properties which are based on other classes? I mean:

class:Location() {
  public string x
  public string y
}

class:Vehicle() {
  public Location location
  public string name
}

Is it possible at all?

Thank you.

@constrict0r
Copy link

constrict0r commented Aug 13, 2018

@niieani
Copy link
Owner

niieani commented Aug 13, 2018

@constrict0r, that's some hefty work indeed. Pretty cool!
@rbukovansky to answer your questions:

  1. creating collections of class instances is a bit tricky for now, but you can capture the definitions of instances (result of declare -p YOUR_VARIABLE and store them in a normal Array). The instance is sort of "serialized" that way.
  2. second is possible and should just work as long as you initialize your type before defining the other class. If it doesn't happen, feel free to open an issue, as it's a bug.

@rbukovansky
Copy link
Author

@constrict0r Thanks, but I'm not sure, which question your answer answers. 🤷🏻‍♂️ Could you please elaborate a little bit more? Thank you!

@niieani So, you mean I need to:

  1. Create Class Location
  2. Create an object of class Location
  3. Set its properties
  4. Create Class Vehicle
  5. Create an object of class Vehicle

@constrict0r
Copy link

constrict0r commented Aug 14, 2018

@rbukovansky , something like this?:

source "$( cd "${BASH_SOURCE[0]%/*}" && cd .. && pwd )/lib/oo-bootstrap.sh"
import util/class

class:Location() {
public string x
public string y
}
Type::Initialize Location

class:Vehicle() {
public Location location
public string name

Vehicle.getter() {
@return:value $(this location toString)
}

Vehicle.Set() {
[reference] toSet
this location x = $($var:toSet x)
this location y = $($var:toSet y)
}
}
Type::Initialize Vehicle

string xSample=33
string ySample=55

Location locationSample
$var:locationSample x = $xSample
$var:locationSample y = $ySample
echo '--------------'
$var:locationSample

Vehicle vehicleSample
$var:vehicleSample Set locationSample
echo '--------------'
$var:vehicleSample

Results:

([__object_type]="Location" [x]="33" [y]="55" )

([location]="([0]=\"([__object_type]=\\\"Location\\\" [x]=\\\"33\\\" [y]=\\\"55\\\" )\")" [__object_type]="Vehicle" )

@rbukovansky
Copy link
Author

@constrict0r Holy crackers! 😮 Thanks a lot! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants