Example of how to create a module

Monkey Forums/Monkey Programming/Example of how to create a module

dooz(Posted 2012) [#1]
Is there an example of how to create a module? I've seen post directing you to look at diddy, but I mean how do you actually make the connection between the externs, the actual libraries needed, packaging it all up with what tran does, etc.?

Thx


Jesse(Posted 2012) [#2]
simple:
create a class, group of classes, function or functions put it in a file. create a folder with the name same as the file put the file in the folder, put the folder in the monkey module folder or in the same folder as your project.

you can also create a master folder with subfolders and you can call the sub modules like this

[monkeycode]
import masterfolder.childfolder
[/monkeycode]

the child folder being the module.


dooz(Posted 2012) [#3]
Hi, I mean something that calls on libraries on each platform, e.g. SQLite. I've seen in other modules, there is a file with extern functions, calling into specific functions in libraries on each platform. For example, if I create a DB library that calls SQLlite, what else do I need to do? Is it documented anywhere?

Thx


Gerry Quinn(Posted 2012) [#4]
You've got to make an extern class in Monkey that 'shadows' a class in native code.

Look at mojo.input for an example: it starts:

Extern
Class InputDevice="gxtkInput"

...and the class just contains method prototypes, i.e. the name and parameter list of each method, with no actual code.

Now in the native code of each language there's a real class called gxtkInput that has all the named methods.

So I guess you would have a class called SqlManager, and functions such as LoadDB( dbName ) and DoQuery( sqlQuery ) or whatever way you want to set it up.


MikeHart(Posted 2012) [#5]
Please note that if you depend on static libraries to be linked to your native code, Monkey by default is not able to link them automatically. You need to modify the build project files.