Thinking of buying in

Community Forums/Monkey Talk/Thinking of buying in

col(Posted 2012) [#1]
Hiya all monkey fans,

I'm thinking of getting myself a copy. Been thinking for a little while now, but I have a ( maybe some ) question first.

I assume, from what I've seen being done, that Monkey can access the low level native apis and stuff. I'd like to know how objects created at the low level, ie outside of the Monkey language, fit in with your Monkey classes/objects. Do you write wrappers, or are there other means?.

Using BlitzMax, I know how you to use external language objects ( say c/++ structs. c++ classes, and operating systems 'objects' ), so I'm wondering what mechanisms does Monkey use to do the same thing.

Cheers!!


ziggy(Posted 2012) [#2]
I don't know for others, but in C# it's just as easy as externing them:

file mycsharpfile.cs C#:
class MyClass {
    
    public void MyMethod(string parameter1) {
        DoStuff();
    }
    
    public static bool Calculate(int value1) {
        return (value1 * 2)>200;
    }
}


[monkeycode]Import "mycsharpfile.cs"
Extern
Class MyClass
Method MyMethod:Void(parameter1:String)
Function Calculate:Bool(value1:Int)
End[/monkeycode]

Last edited 2012

Last edited 2012


MikeHart(Posted 2012) [#3]
Not sure if you can read this post, but it explains it pretty good:

http://www.monkeycoder.co.nz/Community/posts.php?topic=4023

Btw., there are no POINTERin Monkey, so if you need to work with some, then you have to become creative. Also you can't bind any static libraries from within your monkey source code. You would need to alter the created project file that is produced from Monkey when you build a project.


col(Posted 2012) [#4]
Thanks guys,

Sounds good so far.

I knew there may be more questions :)


in C# it's just as easy as externing them:



So it's a good assumption it's the same for other languages? And.. what compiler would be used to compile say some c/#/++ code? for say a windows target? gnu compilers ? vs compilers? EDIT:- which would mean I need to download each seperate compiler to give me the abiility to compile to a respective target?

Does monkey work by including the necessary ( os ) headers for the respective target? meaning that all the functions/classes and objects also in those headers are also then available within the Monkey source too via the techniques as above too? or is there an abstraction level between them?


Btw., there are no POINTERin Monkey, so if you need to work with some, then you have to become creative.


So pointers are possible but not native? Hmm.
Ok...
To keep it simple, say I'm targeting a windows machine, and I call a windows system function that returns me an instance of a class or a struct. I would write a simple 'extern function' as in the link from MikeHart to access that function. But the function would return a class object, or return a class via a function parameter, we don't have native pointers, so I'd have to use another language to handle that function so that I can gain access to the object in Monkey code?

Last edited 2012


therevills(Posted 2012) [#5]
So it's a good assumption it's the same for other languages?

Yep, it is. Check out the Diddy repo: ExternFunctions and native code:

https://bitbucket.org/swoolcock/diddy/src/cf2eee2177610e131be1ff1cdac11dd8104afb43/src/diddy/externfunctions.monkey?at=default

https://bitbucket.org/swoolcock/diddy/src/cf2eee2177610e131be1ff1cdac11dd8104afb43/src/diddy/native?at=default

And.. what compiler would be used to compile say some c/#/++ code?

For the GLFW target Monkey uses Visual C++, and can use MINGW. For the XNA target it uses C#.


col(Posted 2012) [#6]
Sounds good again :P

One more thing, out of interest really as it's not a deciding factor, Monkey can handle callbacks yes? Into Class Methods too?

EDIT:- I mean callbacks from other languages into Monkey. And can you call Monkey class methods/functions directly from the other language. The examples show Monkey calling external functions, can it be done the other way too?

Last edited 2012


ziggy(Posted 2012) [#7]
@col: As far as I know, Yes. But it is not "that" easy. Monkey does not have functiona pointers, but the translation to the native language is sort of easy to follow. bb_ is usualy the prefix for each method, and they are translated to regular classes in the target languages.
Anyway, I haven't investigates this profusely, so don't take my words as a proven fact.


col(Posted 2012) [#8]
Ok, thanks Ziggy.


ziggy(Posted 2012) [#9]
By the way, not having function pointers is something that should not give any problem, becouse it can be done by using Interfaces or by using method calls by using reflection.


MikeHart(Posted 2012) [#10]
I can confirm that you are able to create classes in Monkey and native code, where the native code can call back to a Monkey class method. The mojo.App class with its OnRender, OnUpdate and other On.. methods is a good example.


col(Posted 2012) [#11]
Thats cool, thanks. I only have the demo so could only look at the javascript target source, and yes it certainly looks that way.


Chroma(Posted 2013) [#12]
I would definitely buy it col. I'm sticking with Monkey 100% now. It's nice to be able to compile for PC, iOS, Android, XNA, Flash, Html5 all in the blink of an eye.


*(Posted 2013) [#13]
I am also using it 97% of the time, the last 3% is server code that at the moment cannot be done on monkey