Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SuperStrict
- Framework brl.blitz
- Import brl.standardio
- Type TWaffle
- Field m_delishushness:Int
- Method GetDelishushness:Int()
- Return m_delishushness
- End Method
- Method SetDelishushness(delishushness:Int)
- m_delishushness = delishushness
- End Method
- ' This is a sort-of wacky way to create objects, but it is quite useful
- Method Create:TWaffle(delishushness:Int)
- SetDelishushness(delishushness) ' We don't have to do 'Self.SetDelishushness' here because we are already in the 'Self' scope; though you could do that if you so wished
- Return Self ' 'Self' refers to the actual instance of the type, so in this case we are just returning the object that you created with 'New'
- End Method
- ' This function is only related to the TWaffle type in that it exists within the type's defined space
- ' It does not have any access to any member of the type which is non-static (static being: global, const, other functions)
- Function StaticFunction:Int()
- Print("ohai!")
- Return 42
- End Function
- Function CreateWaffle:TWaffle(delishushness:Int)
- Local zewaffle:TWaffle = New TWaffle
- zewaffle.SetDelishushness(delishushness)
- Return zewaffle
- End Function
- End Type
- Local mywaffle:TWaffle
- mywaffle = TWaffle.CreateWaffle(9) ' I don't particularly like this way of creating objects, as saying 'TWaffle.CreateWaffle' is a bit redundant
- mywaffle = New TWaffle.Create(9) ' This is a more OO approach (note that you could call the above static function 'Create' instead of using the method, but this is how I would do it)
- mywaffle.SetDelishushness(10000) ' Calling a method of the object
- Print(mywaffle.GetDelishushness()) ' Calling a method of the object
- Print(mywaffle.m_delishushness) ' Accessing the field directly
- Print(TWaffle.StaticFunction()) ' You do not need to create a new instance of the type to call functions..
- Print(mywaffle.StaticFunction()) ' .. But you can if you want to. Note that the static function has no knowledge of the instance's members.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement