Sections of native code (Extern?)
Monkey Forums/Monkey Programming/Sections of native code (Extern?)
| ||
Hi everyone, as far as I understand, I can use Extern to write non-monkey code but I am not actually sure how I go about doing this. I've looked through the docs but I am unable to make sense of it. Is anyone able to post a quick example of Monkey code calling a function that has been written in native code? Thanks :) |
| ||
Example: JavaScript: function Hello(){ alert("Hello World"); }; Monkey: Import "myJavaScript.js" Extern Function HelloWorld:Void() = "Hello" |
| ||
Cheers Bruzard :) So calling HelloWorld() from within the monkey code, will run Hello() from the js code? |
| ||
Your Monkey function is called "HelloWorld()" and calls the js function "Hello()" |
| ||
On a similar note: has anyone found a way to store a native object in/as a monkey object? |
| ||
For native objects I usually mimic the mojo model and create monkey class extensions of native objects. |
| ||
hi beaker, im currently working on this also. in current progress, (i am wrapping cocoa elements and need to access them inside monkey) i tried it very similar like in the mojo module. Class iMButton for example holds the pointers from UIButton and handles it, by wrapping all needed functions to monkey.. for example iMButton::SetCaption(string caption) will set the private class var pointer UIButton *mybutton; with mybutton.text = caption.ToNSString(); So something like #import <UIKit/UIKit.h> Class iMButton { Private UIButton *button Public void SetCaption(string caption) } iMButton::SetCaption(string caption) { button.text = caption.ToNSString(); } and in monkey i would then wrap the SetCaption Void. |
| ||
I did the same - in my case it was to load a text file in Flash. (My code is probably rubbish as I know nothing about ActionScript, but it does work.) Monkey code: Flash code: By the way, does anyone know a clean way to write text in Flash? I modified mojo in order to use setClipboard() inside the mouse event handler, thus obeying Adobe's rule that it can only be called from a user-initiated event handler. There's probably a way to make an invisible button in Flash without messing with mojo, though. |