IoLanguage / io

Io programming language. Inspired by Self, Smalltalk and LISP.
http://iolanguage.org
Other
2.66k stars 298 forks source link

Writing C/C++ addons (a question) #365

Closed ales-tsurko closed 6 years ago

ales-tsurko commented 6 years ago

Hi, Is there any updated documentation on writing addons? All that I've found rely on AddonBuilder, which seems doesn't available anymore. I mostly don't understand the building/linking part. Also should I install the addon globally in the io/lib or it's somehow possible to include it in my project? If there is no any could you @stevedekorte wrote some documentation on writing addons please? At least some cursory look.

stevedekorte commented 6 years ago

I never got around to writing those and not sure I will anytime soon, sorry. I’d recommend checking out one of the smaller addons like Blowfish. It should be pretty straightforward.

IoBlowfish.c is the important bit. It defines the constructor, destructor and other methods for the Blowfish object. IoBlowfishInit.c defines IoBlowfishInit() which is used to initialize the addon and add a reference for it to the Io namespace passed in by the context argument.

The io folder contains an Blowfish.io file which will setup the proto with any additional io side methods after it’s been added to the namespace.

The CMakeLists.txt file tells the build system about the source, headers and dependencies.

This pattern would just be repeated for any new addon, though if you need to hold references to Io objects, you’ll need to implement a mark method so the garbage collector can mark them (the fnmatch addon has an example of this).

ales-tsurko commented 6 years ago

Thanks for this little explanation! I have one more question. Considering I successfully compiled my addon. Can I use it in my project locally? I mean, I have this compiled addon as a dynamic library — how to let Io know about this object?

stevedekorte commented 6 years ago

IIRC, you should only need to add an entry for it in addons/CMakeLists.txt and compile/install Io. It will install it with all the dlls for the addons.

ales-tsurko commented 6 years ago

Sorry I was not clear... By "locally" I meant "to distribute it with my Io code, that depend on the addon". Strictly speaking can I compile an addon and include it in my project without recompilation of Io itself? It's more about distribution — if a user has already installed Io, how can he/she install my addon? To be more specific. I'm writing an Io library for live coding music. I need to write some bindings for MIDI, OSC etc. C/C++ libraries. I'd like to split the project in multiple modules. And add these modules as dependencies to my main Io project's code. I'd like to compile those native addons locally (i.e. inside of the projects folder, considering that Io is already installed). So how to distribute such a library then? It's somehow possible to let users, who already have Io on their systems, download my project, compile all the dependend native addons without recompiltation Io itself and use the library?

stevedekorte commented 6 years ago

Oh, I'm not sure how to do that as it may depend on the particular OS and how it deals with dynamic linking. Many OSes hard code the dll path which is problematic for user vs root installed dlls. I would just compile a static version of Io with the addons you want and distribute/embed that with your app. DLLs are troublesome.

Overall, I'd recommend using Javascript and Node.js instead as I'm no longer maintaining Io and JS is very fast, widely used and supported, and has enough of the high level language features to be highly productive in.

Also (FWIW), with todays JS runtimes, I would bet you could even do the all the realtime sound processing from JS if you used the right libraries and byte array primitives.

ales-tsurko commented 6 years ago

Thanks for the advice! This part that I'm working on now is just a part of a future big project. A modular digital audio workstation that I've planned for a long time. I started with JS+NW.js and SuperCollider as a sound engine and internal scripting language. But working on a different JS projects, I've found it not suitable for my project, so I chosed Nim as the main language for the application and Io as an internal scripting language. I'll still use SuperCollider-server as an audio engine, but planning to replace the SuperCollider language with Io as a client. As for the library — I would like to make it open source and freely available (besides of the proprietary application itself). I've planned my own language as a scripting one, so it's not scary for me that Io is not maintened — it's simpler to support Io, than write a new language from scretch. Also Io is very expressive and at the same time is very simple to learn for non-programmers. So I have already big plans with Io:))

stevedekorte commented 6 years ago

Ok, glad to hear it's helpful :)

ales-tsurko commented 6 years ago

If someone in the future will look for this, I've updated Eerie, that makes not only possible the distribution, but also the development of native addons a lot easier. It uses a little bit modified version of the old AddonBuilder that automagically does all the necessary linking and building part. All that's needed now to make an addon is:

stevedekorte commented 6 years ago

Thanks Ales. I've added a link to Eerie: http://iolanguage.org/links.html

ales-tsurko commented 6 years ago

Thanks! BTW, the author of Eerie is Josip Lisec, I'm just the maintainer of the updated fork :)