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