Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Gideros Plugins with the use of C++ library's — Gideros Forum

Gideros Plugins with the use of C++ library's

MillerszoneMillerszone Member
edited October 2011 in General questions
I was going through the Gideros WiKi and found this:
This would be huge.

Oh, I also found this which can be helpful :-D


  • gorkemgorkem Maintainer
    edited October 2011
    I was going through the Gideros WiKi and found this:
    This would be huge.
    Couldn't stress it more.

    While that page is incomplete, Atilim is silently working on the plugin support which will enable 3rd party C++ code or library to be seamlessly used within Gideros. This will be a huge impact in terms of availability and extensibility of the platform.

    In our SVN this plugin support is currently nothing but a "hello world" example, and definitely we need some more time to implement fully. According to our roadmap, it'll be ready for the next release.

    Oh, I also found this which can be helpful :-D
    I must say that this is a global problem ;)

    Thanks for heads up.
  • Can't wait for the plugins!
  • gorkemgorkem Maintainer
    Edit: Each plugin can be one of C++, Java or Objective-C code, not only C++.
  • Java will only be available for android i guess?
  • atilimatilim Maintainer
    Java will only be available for android i guess?
    exactly :)
  • i run into the problem that i would be willing to use a c++ library, not only on the desktop player. is there an example how to do that (for android mainly but i'm also interested if that can be done cross-platform so that it will work later for ios too).

    Likes: brigosx

    +1 -1 (+1 / -0 )Share on Facebook
  • so after further search i'm assured that c++ can be used as a plugin for all platforms, but is there an example on how to do that, because that i did not find. the example i've found is only for the desktop player.
    like the tnt particle engine is written in c and then converted to plugins for all platforms. i want to do the same but with another c library. please help.
  • @keszegh: I think you need to look at this thread for plugins for the desktop player.

    I should also point out that this thread is 18 months old (and as such, much of the content could be out of date). Maybe you should have started a new thread to avoid confusing people who like me started reading this thread from the start.
  • @scouser, you may be right. i just don't like to start new topics when not necessary, the title of this one fits perfectly my question. if someone else wants as well i can move my questions to a new topic.

    in any case i'm looking for a documentation where it is explained how to use a cpp library across all platforms (as a plugin), not just for desktop player. assuming that i have almost no knowledge of cpp (except that i can read a cpp code probably).
  • ar2rsawseenar2rsawseen Maintainer
    edited April 2013
    @keszegh so what you need is actually bind c++ library to lua.

    Once that is done, for ios, you simply add cpp files to the xcode project and thats it.

    For Android, it's the same as creating android plugin, you need to create Android.mk file pointing to your cpp files and then run Android NDK to compile it to .so file that can be included in Android project.

    More on Android plugins and compiling them:

    And that's about it in most cases.
  • keszeghkeszegh Member
    edited April 2013
    that android tutorial is quite detailed, so i could copy paste basically when i needed it for an earlier project with java plugin, yet it is for using java and so it contains some stuff that is probably not needed or needed somehow differently. so it will still be a hard time for me to make it work, that's my impression.
    btw i may want to use this polygon clipping library, which also has a lua-binding:
    (actually i would prefer to use http://www.angusj.com/delphi/clipper.php as it has a free licence, but there is no lua binding for it)

    i think generally there are many cpp libs, so it would be maybe useful to make a tutorial how to make a plugin from them (mainly so plugin for android).
    would it be possible to make such a tutorial? i understand that one part is lua-binding which is explained around the net and is a different cup of tea, but given the lua-binding how to do the rest, that's what i would be happy to see (assuming minimal java and cpp knowledge).
  • ar2rsawseenar2rsawseen Maintainer
    @keszegh I see.
    well if lua binding is already provided, it won't work out of the box and should also be a little modified as gideros plugin.

    It could differ from binding to binding but in most cases it should have included gideros.h

    and couple of additional methods:
    //register c functions
    LUALIB_API int luaopen_plugin(lua_State *L)
      //where funcs is function list
      luaL_register(L, "somePluginName", funcs);
      return 1;
    //here we load a package
    static void g_initializePlugin(lua_State *L)
        //get global package object
        lua_getglobal(L, "package");
        lua_getfield(L, -1, "preload");
        //put our plugin name inside with a callback to
        //registering C functions
        lua_pushcfunction(L, luaopen_plugin);
        lua_setfield(L, -2, "somePluginName");
        lua_pop(L, 2);
    //and here we free everything we need to free
    static void g_deinitializePlugin(lua_State *L)
    And probably need to remove the initialization of that binding

    Now about Android, it's actually should be quite easy. Export project as Android project, copy and paste everything from Gideros installation folder/sdk/include to project's jni folder.
    Create Android.mk file with minimum this contents:
    LOCAL_PATH := $(call my-dir)
    # Gideros Shared Library
    include $(CLEAR_VARS)
    LOCAL_MODULE            := gideros
    LOCAL_SRC_FILES         := ../../libs/$(TARGET_ARCH_ABI)/libgideros.so #may need to provide correct path
    # Plugin
    include $(CLEAR_VARS)
    LOCAL_MODULE           := exampleplugin #plugin name
    LOCAL_ARM_MODE         := arm
    LOCAL_CFLAGS           := -O2
    LOCAL_SRC_FILES        := file1.cpp file2.cpp #list cpp files here
    LOCAL_LDLIBS           := -ldl -llog
    Then install Android NDK from here: http://developer.android.com/tools/sdk/ndk/index.html

    And either set it up like this: http://mobilepearls.com/labs/ndk-builder-in-eclipse/

    Or navigate through command line to your project's jni folder and run ndk-build

    And that should be it. Your project's libs folder should contain so files in each proper armeabi folder.

    But what you try to accomplish (clipping) I think may not be possible, due to probably that it uses openGL to draw and in Gideros case, the Gideros openGL surface is drawing api is not exposed, so it won't work. There is a plan to expose it in the future, but then probable even more modification must be needed for current available library.
  • keszeghkeszegh Member
    edited April 2013
    thanks @ar2rsawseen,
    this may be quite enough for a start. you say that lua binding to use with gideros differs from lua binding in general (or that it is not a universal thing to bind, it depends on usage). so is there some general rule how to do the binding for gideros? or what you wrote above is basically all of that (remove initialization, add gideros.h and the above mentioned additional methods)?

    sidenote about the clipping libraries:
    about clipping, the nice thing is that this is a clipping library for polygons as data structures, so it is opengl etc independent. once clipping is computed using this library theoretically we get back a polygon data (union of polygons actually), e.g. the list of the triangles of one of its triangulations and then we can use gideros meshes to render this fast even on current gideros version. this should be good for colored meshes, if one wants texturing, then it should be again relatively easy to compute the texture coordinates of the vertices and thus for each vertex of each triangle in the mesh.

    overall this shall be a useful library for other people too, i want to use it to make a 2d dynamic lighting/shadow engine, but my plans are rather theoretical at this point, i even did not make up my mind about which framework to use. i prefer gideros, but lack of info about the time of appearance of desktop export takes me back a little, so i contemplate haxenme as well. anyway most probably i won't start to realize the project soon, but i had a basic tech-demo years ago with as3 and i thought that maybe i can rewrite it more efficiently, now using gideros and one such clipping library (previously i used blending modes to emulate clipping in as3, but that was incredibly slow) just to see whether it could perform well on mobiles.

  • ar2rsawseenar2rsawseen Maintainer
    @keszegh oh ok I get it now.
    And yes, that probably should be the basic to replace for Gideros, but based on other bindings there might be different specifics, as there are more than one way to bind something.

    If you run into trouble, you can post here and I'll try to help as much as I could ;)
  • @ar2rsawseen, trying this may happen much later or even never, but if/when i encounter any problems, you will hear about it. thanks for the help.
Sign In or Register to comment.