Binding Lua To C++

Cairo bindings, which are expected to follow the bindingguidelines as closely as possible, are available for variouslanguages:

  • Ada : CairoAda

  • C++ : cairomm

  • Common Lisp : cl-cairo2, cffi-cairo

  • COM-Wrapper : aka 'ActiveX-dll' ... easiest to use with VB5/6 or VBA,comes with cairo as a 'satellite-dll' (compiled with StdCall-callingconvention)download-page: (a large VB-Democode-Tutorial is available there too)

  • Harbour : hbcairo

  • Haskell : hscairo

  • Java : org.freedesktop.cairo in java-gnome

  • C# : https://github.com/zwcloud/CairoSharp

    • Mono and .NET bindings used to be bundled with the Monodistribution in the Mono.Cairo library, but this is no longermaintained.
    • At one point, bindings had also been provided atNDesk.
  • Nickle : cairo-nickle

  • Objective Caml : cairo-ocaml

  • Perl : cairo-perl

  • PHP : cairo-php

  • Prolog : PLcairo

  • Python : pycairo,qahirah high-level Pythonic binding, cairocffi binding created withCFFI, pygobject includes Cairo binding.

  • Ruby : rcairo

  • Scheme: guile-cairo

  • Ypsilon Scheme ships with Cairo bindings

  • Squeak : Rome

  • Digitalmars D: cairoD - simple wrapper for D direct C API

  • Lua : Lua-Cairo, Lua-OOCairo, LuaCairo

  • LuaJIT: luapower/cairo

Ip2region is a offline IP location library with accuracy rate of 99.9% and 0.0x millseconds searching performance. DB file is ONLY a few megabytes with all IP address stored. Binding for Java,PHP,C,Python,Nodejs,Golang,C#,lua. Binary,B-tree,Memory searching algorithm. Nodejs python c java rust golang php lua php-extension ip-address clang ip. You're not limited to strict C/C rules, you can have same method doing different job depending on exact arguments. The semantic of the call would express some higher-level concept. When doing such flexible methods, fully automatic binding are mostly useless. Say, you can accept a variety of objects as arguments.

  • Python : python_pixman is a high level pixel-manipulationlibrary (examples)

Since cairo is only a drawing library, it can be quite useful tointegrate it with a graphical user interface toolkit.

  • FLTK has full cairo support (through '--enable-cairo' compileswitch).

  • GNUstep bindings: http://cvs.savannah.gnu.org/viewvc/gnustep/gnustep/core/back/Source/cairo/

  • GTK+ 2.8+ has full support for cairo.

Lua Binding

Overview

Lua Library

All the IM functions are available in Lua, with a few exceptions. We call it ImLua. To use them the general application will do require'imlua', and require'imluaxxxx' to all other secondary libraries that are needed. The functions and definitions will be available under the table 'im' using the following name rules:

New functions (without equivalents in C) were implemented to create and destroy objects that do not exist in C. For instance functions were developed to create and destroy palettes. All the metatables have the 'tostring' metamethod implemented to help debuging. The imImage metatable has the 'index' metamethod so you can address its data directly in Lua. Some functions were modified to receive those objects as parameters.

Also the functions which receive values by reference in C were modified. Generally, the values of parameters that would have their values modified are now returned by the function in the same order.

Notice that, as opposed to C, in which enumeration flags are combined with the bitwise operator OR, in Lua the flags are added arithmetically.

In Lua all parameters are checked and a Lua error is emitted when the check fails.

All the objects are garbage collected by the Lua garbage collector.

Initialization

Lua 5.1 'require' can be used for all the ImLua libraries. You can use require'imlua' and so on, but the LUA_CPATH must also contains the following:

Also compatible with Lua 5.2 and 5.3, just replace the '51' suffix by '52' or '53'.

The LuaBinaries distribution already includes these modifications on the default search path.

If you are using another Lua distribution you can use the environment:

Or you can set it in Lua before loading iup modules:

Bending luan

The simplest form require'im' and so on, can not be used because there are IM dynamic libraries with names that will conflict with the names used by require during search.

Additionally you can statically link the ImLua libraries, but you must call the initialization functions manually. The imlua_open function is declared in the header file imlua.h, see the example below:

Calling imlua_close is optional. In Lua it can be called using 'im.Close()'. It can be used to avoid a memory leak. See imFormatRemoveAll in File Formats. (since 3.9.1)

imImage Usage

imImage structure members are accessed using member functions in Lua. For instance:

In CIn Lua
image->widthimage:Width()
image->heightimage:Height()
image->color_spaceimage:ColorSpace()
image->data_typeimage:DataType()
image->has_alphaimage:HasAlpha()
image->depthimage:Depth()

Data can also be accessed in Lua in two different ways.

First, using data indexing with plane, line and column. image[plane] returns an object that represents an image plane. image[plane][line] returns an object that represents an image line of that plane. And finally image[plane][line][column] returns an object that represents the pixel value of the column in the line of that plane. All indices use the same start as in C, i.e. all start at 0. Only the pixel value can has its value changed. When data_type is IM_CFLOAT then value is a table with two numbers.

Second, all pixels can be changed or retrieved at once using the 'image:SetPixels(table)' and 'table = image:GetPixels()' member functions. The number of elements in the table must be equal to 'width * height * depth'. If there is alpha the depth must be incremented by 1. If data_type is IM_CFLOAT depth must be duplicated. Data organization is the same as in the image->data member. The table indices starts at 1. (Since 3.9)

Integration with CDLua

In CDLua there is an additional library providing simple functions to map the imImage structure to the cdBitmap structure. And some facilities to draw an image in a CD canvas. See also the CD documentation and the IM Lua 5 Binding reference.

Color values and palettes can be created and used transparently in both libraries. Palettes and color values are 100% compatible between CD and IM.

Reference

Lua C++ Api

C++

How To Use Comb Binder

See also the ImLua 5 Binding Reference.

Bending Luan