• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Extern Method

zxretrosoft

Member
Joined
Jul 1, 2017
Messages
32
Hi guys,
just a little thing please ;)

How do I do #include external methods?

I would like to put one great method into another file and then join it to class.
Thanks!
 
You can't just external methods. What you can do is, put that method into its own class, and add an extend to your other class.
 
I have a question concerning this:

Would it be possible to make something like disguised late bound Methods? E.g. you write
Code:
Method <MyType>MyWhatsoeverMethod:Void(parameter:Int)
    funkystuff = parameter * doMagic
End
and it's translated into
Code:
Function __MyWhatsoeverMethod:Void(__SELF__:MyType, parameter:Int)
    __SELF__.funkystuff = parameter * doMagic
End Function

And every call of instanceOfMyType.MyWhatsoeverMethod(i) is translated into __MyWhatsoeverMethod(instanceOfMyType, i)

This way, you could provide functionality to existing modules and still keep the OOP spirit.

One hard part would be to convince the IDE it should treat those as every other method of that type (when it comes to autocompletition).
 
Maybe, but to me it looks like an extremely dirty hack :D
So in the end it should inject a method into a class from outside … maybe something like this could be implemented in a better way … will have a look into that.
 
I think with some work it could be possible to modify a class from outside. Maybe like this:
Code:
Class Foo
   ...
End

Interface IBar
    Method Bar:Void()
End

Modify Class Foo Implements IBar 'class Foo now implements IBar
    Field x:Int 'add a field to class Foo
    Method Bar:Void() 'add a method to class Foo
        Print x
    End
End

Function Main:Int()
    Local foo:IBaz = New Foo
    foo.x = 123
    foo.Bar() 'prints 123
    Return 0
End
However this could be risky: if two modules would modify the same class, they could become incompatible.
 
I think this should not be implemented because it could lead into pure chaos.
 
Ah, I think you ment the extension keyword, or?

Indeed, super handy. Would love to have that for CX.
 
Back
Top Bottom