libFAUDES

Sections

Index

Lua Bindings PlugIn
[PlugIns]

Classes

class  faudes::LuaFunctionDefinition
 A LuaFunctionDefinition is derived from FaunctionDefinition to defines a faudes-function to be a luafaudes script. More...
class  faudes::LuaFunction
 A LuaFunction is a faudes-function that executes a luafaudes script. More...

Detailed Description

This plugin generates libFAUDES bindings for the scripting language Lua; see http://www.lua.org. With this plugin, a Lua interpreter may serve as an interactive user interface to libFAUDES data types and functions. The tutorial section includes a number of example scripts to demonstrate libFAUDES access from Lua.

The luabindings plugin also includes the application luafaudes, a variation of the std Lua interpreter that runs FAUDES extended lua scripts. If your target platform is Linux, you really want to re-compile with LBP_LUAGOAL=linux in the Makefile.plugin in order to enable advanced readline support (tab key completion, command history etc).

Example Script

The following script runs a simple synthesis procedure to synthesise a supervisor - sic - for our two simple machines. For examples, see "./plugins/luabindings/tutorial/_*_.lua" and the introduction given on http://www.rt.eei.uni-erlangen.de/FGdes/faudes/luafaudes/index.html

-- read original machine
machine  = faudes.Generator("data/verysimplemachine.gen")

-- prepare two copies
machine1 = faudes.Generator();
machine2 = faudes.Generator();
faudes.Version(machine,"1",machine1);
faudes.Version(machine,"2",machine2);

-- compose overall plant
plant = faudes.Generator();
faudes.Parallel(machine1,machine2,plant);

-- load specification
spec = faudes.Generator("data/buffer12.gen");

-- run synthesis
super = faudes.Generator();
faudes.SupConNB(plant,spec,super);


-- report result
plant:Write();
spec:Write();
super:Write();

Extending Luabindings

When you use the libFAUDES plugin mechanism to implement your algorithms, you may find it useful to include your extensions in the Lua based interface. The wrapper code is automatically generated from so called interface definition files using the tool SWIG; see http://www.swig.org.

For data types with a tailored user interface, you will need to provide interface definitions directly to define the way a user may interact with variables of the respective type. For functions that are registered with the faudes run-time interface, the interface definitions will be generated by the build system. In both cases, the additional code required to integrate your plugin into luafaudes is minimal.

The below is from the example plugin and directly defines the interface for the AlternativeAccessible function. For more detailed information, see the Plug-In Example

// Set SWIG module name
// Note: must match libFAUDES plug-in name
%module example

// Indicate plugin to rti function definitions
#ifndef SwigModule
#define SwigModule "SwigExample"
#endif

// Load std faudes interface
%include "faudesmodule.i"

// Include rti generated functioninterface 
#if SwigModule=="SwigExample"
%include "../../../include/rtiautoload.i"
#endif

// Define interface to additional functions
void OtherFunction(vGenerator& rGen, rEventSet& rAlph);
bool IsGoodTest(vGenerator& rGen, rEventSet& rAlph);
...

Build System

Since not every libFAUDES based application requires luabindings, the luabindings plugin does not add code to libFAUDES itself but compiles to a seperate archive named libluafaudes (.a,.so,.dll)

The build system organises the compilation of the luabindings plugin in two stages:

  • At stage one, SWIG is used to generate the wrapper code. Since the plugin ships with appropriate wrapper code, this stage only needs to be processed if you want to generate additional bindings for you plugin. You will need SWIG version 1.3.36 installed on your system; see http://www.swig.org. Use make luabindings-clean and make luabindings-prepare to re-build the wrapper code. This stage is also processed by the configuration procedure, e.g. make dist-clean and make configure.
  • At stage two, the wrapper code and Lua is compiled to the archive libluafaudes.h. The plugin includes the lua sources, no additional software requirements are imposed. This stage is processed by the std build procedure, eg make clean and make.

Advanced Topic: RTI extensions by Lua functions

The Lua environment is designed to support both calling C code from a Lua script as well as calling Lua code from a C application. The latter direction is used by faudes::LuaFunction and faudes::LuaFunctionDefinition objects to extend libFAUDES by Lua scripts that register with the libFAUDES run-time interface. Thus, libFAUDES applications that interface to libFAUDES via the RTI can be transparently extended by Lua scripts.

License

The luabindings plugin is distributed with libFAUDES. All code except the Lua sources are provided under terms of the LGPL.

Copyright (c) 2008,2010 Thomas Moor.

Lua sources are included for convenience and come under terms of the following MIT License:

License for Lua 5.0 and later versions Copyright (c) 1994-2008 Lua.org, PUC-Rio.

Permission 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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE 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.

libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3