lbp_include.h
Go to the documentation of this file.
1/** @file lbp_include.h Includes all luabindings plug-in headers */
2
3/*
4 ****************************************************
5 Convenience header file that includes all headers
6 relevant to the luabindings plug-in.
7
8 (c) Thomas Moor 2008-2025
9 ****************************************************
10 */
11
12
13#ifndef FAUDES_LBP_INCLUDE_H
14#define FAUDES_LBP_INCLUDE_H
15
16#endif
17
18
19
20/**
21
22@defgroup LuabindingsPlugin Lua Bindings Plug-In
23
24
25@ingroup AllPlugins
26
27<p>
28This plug-in generates libFAUDES bindings for the scripting language Lua;
29see http://www.lua.org.
30With this plug-in, a Lua interpreter may serve as
31an interactive user interface to libFAUDES data types and functions.
32The tutorial section includes a number of example scripts to demonstrate
33libFAUDES access from Lua.
34</p>
35
36<p>
37The luabindings plug-in also includes the application luafaudes, a variation of
38the std Lua interpreter that runs FAUDES extended lua scripts. If your target platform
39is Linux, you really want to re-compile with LBP_LUAGOAL=linux in the Makefile.plug-in
40in order to enable advanced readline support (tab key completion, command history etc).
41</p>
42
43@subsection SecLuabindingsIntro1 Example Script
44
45The following script runs a simple synthesis procedure to
46synthesise a supervisor - sic - for our two simple machines.
47For examples, see "./plugins/luabindings/tutorial/_*_.lua" and the
48introduction given on http://www.rt.eei.uni-erlangen.de/FGdes/faudes/luafaudes
49
50@code
51
52-- read original machine
53machine = faudes.Generator("data/verysimplemachine.gen")
54
55-- prepare two copies
56machine1 = faudes.Generator();
57machine2 = faudes.Generator();
58faudes.Version(machine,"1",machine1);
59faudes.Version(machine,"2",machine2);
60
61-- compose overall plant
62plant = faudes.Generator();
63faudes.Parallel(machine1,machine2,plant);
64
65-- load specification
66spec = faudes.Generator("data/buffer12.gen");
67
68-- run synthesis
69super = faudes.Generator();
70faudes.SupCon(plant,spec,super);
71
72
73-- report result
74plant:Write();
75spec:Write();
76super:Write();
77@endcode
78
79@subsection SecLuabindingsIntro2 Extending Luabindings
80
81
82When you use the libFAUDES plug-in mechanism to implement your algorithms,
83you may find it useful to include your extensions in the Lua based
84interface. The wrapper code is automatically generated from so called interface
85definition files using the tool SWIG; see http://www.swig.org.
86
87For data types with a tailored user interface, you will need to provide
88interface definitions directly to define the way a user may interact with
89variables of the respective type. For functions that are registered with
90the faudes run-time interface, the interface definitions will be generated
91by the build system. In both cases, the additional
92code required to integrate your plug-in into luafaudes is minimal.
93
94The below is from the example plug-in and directly defines the interface for the
95AlternativeAccessible function. For more detailed information,
96see the <a href="../faudes_algorithm_example.html">Plug-In Example</a>
97
98
99@code
100// Set SWIG module name
101// Note: must match libFAUDES plug-in name
102%module example
103#ifndef SwigModule
104#define SwigModule "SwigExample"
105#endif
106
107// Load std faudes interface
108%include "faudesmodule.i"
109
110// Include rti generated functioninterface
111#if SwigModule=="SwigExample"
112%include "../../../include/rtiautoload.i"
113#endif
114
115// Define interface to additional functions
116void OtherFunction(Generator& rGen, rEventSet& rAlph);
117bool IsGoodTest(Generator& rGen, rEventSet& rAlph);
118...
119
120@endcode
121
122
123
124@subsection SecLuabindingsIntro3 Build System
125
126Since not every libFAUDES based application requires luabindings,
127the luabindings plug-in does not add code to libFAUDES itself but compiles
128to a seperate archive named libluafaudes (.a,.so,.dll)
129
130The build system organises the compilation of the luabindings plug-in in two stages:
131- At stage one, SWIG is used to generate the wrapper code. Since the plug-in ships
132 with appropriate wrapper code, this stage only needs to be processed if you want to
133 generate additional bindings for you plug-in. You will need SWIG version 1.3.36 installed on your system; see http://www.swig.org.
134 Use <tt>make luabindings-clean</tt> and <tt>make luabindings-prepare</tt> to re-build the wrapper code.
135 This stage is also processed by the configuration procedure, e.g. <tt>make dist-clean</tt> and <tt>make configure</tt>.
136- At stage two, the wrapper code and Lua is compiled to the archive
137 <tt>libluafaudes.a</tt>. The plug-in includes the lua sources, no additional software requirements
138 are imposed. This stage is processed by the std build procedure, eg <tt>make clean</tt> and <tt>make</tt>.
139
140
141@subsection SecLuabindingsIntro4 Advanced Topic: RTI extensions by Lua functions
142
143The Lua environment is designed to support both calling C code from a Lua script
144as well as calling Lua code from a C application. The latter direction is used
145by faudes::LuaFunction and faudes::LuaFunctionDefinition objects to extend libFAUDES
146by Lua scripts that register with the libFAUDES run-time interface. Thus, libFAUDES applications
147that interface to libFAUDES via the RTI can be transparently extended by Lua scripts.
148
149
150@subsection LbpLicense License
151
152The luabindings plug-in is distributed with libFAUDES.
153All code except Lua sources are provided under terms of the LGPL.
154
155
156Copyright (c) 2008, 2023 Thomas Moor.
157
158
159Lua sources are included for convenience and come under terms of the following MIT License:
160
161License for Lua 5.0 and later versions
162Copyright (c) 1994-2008 Lua.org, PUC-Rio.
163
164Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
165
166The above copyright notice and this permission notice shall be included in all copies or substantial portions ofthe Software.
167
168THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
169
170
171The luabindings plug-in also provides a variation of
172the advanced readline support, which is Copyright (C) 2004-2006 Mike Pall,
173with the same license as Lua. See also the file lbp_completion.cpp
174
175
176
177*/
178
179
180#ifndef FAUDES_LIBLUAFAUDES_H
181#define FAUDES_LIBLUAFAUDES_H
182
183
184// lua essentials
185#define lua_c
186
187
188// lua essentials
189extern "C" {
190#include "lua/lua.h"
191#include "lua/lauxlib.h"
192#include "lua/lualib.h"
193}
194
195
196// use 5.2.x API in 5.1.x
197#if LUA_VERSION_NUM < 502
198//#define lua_getglobal(l,str) lua_getfield(l, LUA_GLOBALSINDEX, str)
199//#define lua_setglobal(l,str) lua_setfield(l, LUA_GLOBALSINDEX, str)
200#ifndef lua_writestring
201#define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
202#endif
203#ifndef lua_writeline
204#define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
205#endif
206#ifndef lua_writestringerror
207#define lua_writestringerror(s,p) (fprintf(stderr, (s), (p)), fflush(stderr))
208#endif
209#ifndef lua_pushglobaltable
210#define lua_pushglobaltable(l) lua_pushvalue(l, LUA_GLOBALSINDEX)
211#endif
212#endif
213
214// this macro was removed (in some version after 5.1.3 ...)
215#ifndef LUA_QL
216#define LUA_QL(x) "'" x "'"
217#endif
218
219// this macro was introduced (in some version after 5.1.3 ...)
220#ifndef LUA_OK
221#define LUA_OK 0
222#endif
223
224// this macro was introduced (in some version after 5.1.3 ...)
225#ifndef LUA_VERSUFFIX
226#define LUA_VERSUFFIX "_5_1"
227#endif
228
229
230// std streams
231#include <iostream>
232#include <fstream>
233#include <sstream>
234#include <string>
235
236// c libs
237#include <csignal>
238#include <cstdio>
239#include <cstdlib>
240#include <cstring>
241
242// luafaudes: include faudes plus lua addons
243#include "corefaudes.h"
244#include "lbp_addons.h"
245#include "lbp_function.h"
246
247// include declarations for SWIG generated module loaders
248#include "lbp_load.h"
249
250
251// SWIG interface std: programatic exception, see coreaddons.i
252namespace faudes {
253extern FAUDES_API void faudes_throw_exception(const std::string& msg);
254extern FAUDES_API void faudes_dict_insert_topic(const std::string& topic, const std::string& text);
255extern FAUDES_API void faudes_dict_insert_entry(const std::string& topic, const std::string& key, const std::string& entry);
256extern FAUDES_API void faudes_mute(bool on);
257extern FAUDES_API void faudes_console(const std::string& message);
258extern FAUDES_API void faudes_debug(const std::string& message);
259}
260
261// luafaudes debugging facilities
262#ifdef FAUDES_DEBUG_LUABINDINGS
263#define FD_DLB(message) FAUDES_WRITE_CONSOLE("FAUDES_LUA_ERROR: " << message);
264#else
265#define FD_DLB(message)
266#endif
267
268
269
270#endif
#define FAUDES_API
FAUDES_API void faudes_mute(bool on)
FAUDES_API void faudes_debug(const std::string &message)
void faudes_dict_insert_topic(const std::string &topic, const std::string &text)
Definition swg_utils.cpp:57
void faudes_dict_insert_entry(const std::string &topic, const std::string &key, const std::string &entry)
Definition swg_utils.cpp:62
FAUDES_API void faudes_console(const std::string &message)
void faudes_throw_exception(const std::string &msg)
Definition swg_utils.cpp:30

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen