1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 12.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Language" content="en-us">
<title>Lua Binding</title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h2>Lua Binding</h2>
<h3><a name="Overview">Overview</a></h3>
<p>
All the IM functions are available in Lua, with a few exceptions. We call it <strong>
ImLua</strong>. 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:</p>
<pre>imXxx -> im.Xxx (for functions)<br />IM_XXX -> im.XXX (for definitions)<br />imFileXXX(ifile,... -> ifile:XXX(... (for methods)
imImageXXX(image,... -> image:XXX(... (for methods)<br /></pre>
<p>
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 <strong>imImage</strong>
metatable has the "index" metamethod so you can address its data
directly in Lua. Some functions were modified to receive those objects
as parameters.</p>
<p>
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.</p>
<p>
Notice that, as opposed to C, in which enumeration flags are<i> </i>
combined with the bitwise operator OR, in Lua the flags are added
arithmetically.</p>
<p>
In Lua all parameters are checked and a Lua error is emitted when the
check fails.</p>
<p>
All the objects are garbage collected by the Lua garbage collector. </p>
<p>
<span style="color: #ff0000">
</span>
<span style="color: #ff0000"><span style="color: #000000"> </span></span></p>
<h3>
Initialization</h3>
<p>
<strong>Lua</strong> 5.1 "require" can be used for all the <strong>ImLua</strong>
libraries. You can use <b>require</b>"<b>imlua</b>" and so on, but the
LUA_CPATH must also contains the following:
</p>
<pre>"./lib?51.so;" [in UNIX]
".\\?51.dll;" [in Windows]
</pre>
<p>
The <a href="http://luabinaries.luaforge.net/">LuaBinaries</a>
distribution already includes these modifications on the default search
path.</p>
<p>
The simplest form <b>require</b>"<b>im</b>" and so on, can not be used
because there are IM dynamic libraries with names that will conflict
with the names used by <b>require</b>
during search.</p>
<p>
Additionally you can statically link the <strong>ImLua</strong>
libraries, but you must call the initialization functions manually. The <strong><font face="Courier New">
imlua_open</font></strong> function is declared in the header file <strong><font
face="Courier New">imlua</font><font face="Courier New" size="2">.</font><font face="Courier New">h</font></strong>,
see the example below:</p>
<div align="center">
<center>
<table cellpadding="10" cellspacing="0" style="border-width: 0; border-collapse: collapse" bordercolor="#111111" id="AutoNumber1">
<tr>
<td>
<pre>#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
<b><font color="#FF0000">#include <imlua.h></font></b></pre>
<pre>void main(void)
{
lua_State *L = lua_open();
luaopen_string(L);
luaopen_math(L);
luaopen_io(L);
<b> <font color="#FF0000">imlua_open(L);</font>
</b>
lua_dofile("myprog.lua");
lua_close(L);
}</pre>
</td>
</tr>
</table>
</center>
</div>
<h3><a name="Integration with ImLua">Integration with CDLua</a></h3>
<p>In <b>CDLua</b> there is an additional library providing simple functions
to map the
<strong>imImage</strong>
structure to the <strong>cdBitmap</strong> structure. And some facilities to
draw an image in a CD canvas. See also the <a target="_blank" href="http://www.tecgraf.puc-rio.br/cd">
CD documentation</a> and the <a href="doxygen/group__imlua.html">IM Lua 5
Binding</a> reference.</p>
<p>Color values and palettes can be created and used transparently in both
libraries. Palettes and color values are 100% compatible between CD and IM.</p>
<h3>
Reference</h3>
<p>
See also the <a href="doxygen/group__imlua.html">ImLua 5 Binding
Reference</a><span
style="color: #ff0000">.</span></p>
</body>
</html>
|