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!
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
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.
 

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
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).
 

PixelPaladin

New member
CX Code Contributor
3rd Party Module Dev
Joined
Aug 27, 2017
Messages
110
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.
 

PixelPaladin

New member
CX Code Contributor
3rd Party Module Dev
Joined
Aug 27, 2017
Messages
110
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.
 

PixelPaladin

New member
CX Code Contributor
3rd Party Module Dev
Joined
Aug 27, 2017
Messages
110
I think this should not be implemented because it could lead into pure chaos.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
Ah, I think you ment the extension keyword, or?

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