Home

raman

Welcome to your wiki!

This is the default page, edit it as you see fit. To add a page simply reference it within brackets, e.g.: [SamplePage].

The wiki uses Markdown syntax.


  • raman
    raman
    2011-07-29

    eLua-SWIG is a SWIG language extension for eLua. It generates wrappers compatible with the LTR patch supported by eLua.

    This extension introduces two new SWIG switches: -elua and -eluac

    -elua:

    With this switch, the wrapper generated for eLua will support LTR. This extension puts all the C function wrappers and variable get/set wrappers in rotables. It also generates a metatable which will control how these variables are accessed from eLua.

    Wrapping user defined datatype works differently. Wrapping of struct and union requires dynamic creation of metatables in order to manage the manipulation of such objects. Such functions cannot happen from within rotables.

    Example:

    struct point {
    int x, y;
    };

    struct point p1;
    p1.x = 10;
    p1.y = 20;

    In Lua: (When wrapped)

    p1 = mod.point()
    p1.x = 10
    p1.y = 20

    ('mod' is the name of the module)

    p1.x is an operation that is performed by a metamethod. Here, p1 gets its own metatable dynamically.

    To incorporate this functionality, we must trade some amount of ram.

    A tip: The higher the number of C functions that need to be wrapped, the more '-elua' will minimize ram consumption by putting them in rotables (With respect to the SWIG '-lua' language module). In other words, the difference between '-lua' and '-elua' (ram consumption) will be small for smaller modules.

    If you don't care about this feature and want to save ram, use '-eluac'. (the 'c' in the switch is "crass compress")

    '-eluac':

    With this, no matter how huge the module, it will consume no ram. It puts all of the wrappers (function wrappers, structure variable get/set wrappers etc ...) in rotables. To access them from eLua, one must use functions.

    Example:

    To access the point structure above from eLua (wrapper is generated with '-eluac'):

    mod.count_set(0)

    a = mod.new_point()
    mod.point_x_set(a, 10)
    mod.point_y_set(a, 20)

    mod.count_set(1)

    print(mod.point_x_get(a), mod.point_y_get(a), mod.count_get())

    'mod' is the module's name, 'count' is a name of a global variable in C, wrapped for eLua.

     
    Last edit: raman 2011-07-30