From 6cb75c5b3c24940b78ad6c3219fa0471a572b1e2 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Tue, 23 Aug 2016 15:46:51 +0200 Subject: Support for LUA language bindings --- CMakeLists.txt | 1 + src/bindings/CMakeLists.txt | 3 + src/bindings/swig/lua/CMakeLists.txt | 32 +++++++ src/bindings/swig/lua/uscxml.i | 159 +++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 src/bindings/swig/lua/CMakeLists.txt create mode 100644 src/bindings/swig/lua/uscxml.i diff --git a/CMakeLists.txt b/CMakeLists.txt index d5110dc..30fefeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,7 @@ else() endif() OPTION(BUILD_BINDING_JAVA "Build language bindings for Java" ON) +OPTION(BUILD_BINDING_LUA "Build language bindings for Lua" ON) OPTION(BUILD_BINDING_CSHARP "Build language bindings for CSharp" ON) OPTION(BUILD_BINDING_PHP "Build language bindings for PHP" OFF) diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt index 57388f2..e75d8f2 100644 --- a/src/bindings/CMakeLists.txt +++ b/src/bindings/CMakeLists.txt @@ -27,6 +27,9 @@ if (SWIG_FOUND) if (BUILD_BINDING_JAVA) add_subdirectory(swig/java) endif() + if (BUILD_BINDING_LUA) + add_subdirectory(swig/lua) + endif() # if (BUILD_BINDING_CSHARP) # add_subdirectory(swig/csharp) # endif() diff --git a/src/bindings/swig/lua/CMakeLists.txt b/src/bindings/swig/lua/CMakeLists.txt new file mode 100644 index 0000000..344edec --- /dev/null +++ b/src/bindings/swig/lua/CMakeLists.txt @@ -0,0 +1,32 @@ +# generate JNI library and create a jar +# Make from within Eclipse fails miserably with the whole thing + +find_package(Lua) +if(LUA_FOUND) + include_directories(${LUA_INCLUDE_DIR}) +else() + message(STATUS "No Lua headers found - not building Lua wrappers") + return() +endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +SET(CMAKE_SWIG_FLAGS "") +SET(USCXML_LUA_DIR "uscxml") + +# we need ; to produce a space with the package .. weird +SET_SOURCE_FILES_PROPERTIES(uscxml.i PROPERTIES SWIG_FLAGS "-w473") +SET_SOURCE_FILES_PROPERTIES(uscxml.i PROPERTIES CPLUSPLUS ON) +SET(CMAKE_SWIG_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/${USCXML_LUA_DIR}") + +SWIG_ADD_MODULE(uscxmlNativeLua lua uscxml.i) +foreach(LUA_LIBRARY ${LUA_LIBRARIES}) + SWIG_LINK_LIBRARIES(uscxmlNativeLua ${LUA_LIBRARY}) +endforeach() +set_target_properties(uscxmlNativeLua PROPERTIES FOLDER "Bindings") +set_target_properties(uscxmlNativeLua PROPERTIES COMPILE_FLAGS "-DSWIG") + +swig_link_libraries(uscxmlNativeLua uscxml) + +set(USCXML_LANGUAGE_BINDINGS "lua ${USCXML_LANGUAGE_BINDINGS}") +set(USCXML_LANGUAGE_BINDINGS ${USCXML_LANGUAGE_BINDINGS} PARENT_SCOPE) diff --git a/src/bindings/swig/lua/uscxml.i b/src/bindings/swig/lua/uscxml.i new file mode 100644 index 0000000..9774cba --- /dev/null +++ b/src/bindings/swig/lua/uscxml.i @@ -0,0 +1,159 @@ +%module(directors="1") uscxmlNativeLua + +// provide a macro for the header files +#define SWIGIMPORTED 1 + +%include +%include +%include +%include +%include "../stl_set.i" +%include "../stl_list.i" + +// these are needed at least for the templates to work +typedef uscxml::Blob Blob; +typedef uscxml::Data Data; +typedef uscxml::Event Event; +typedef uscxml::Invoker Invoker; +typedef uscxml::IOProcessor IOProcessor; +typedef uscxml::DataModel DataModel; +typedef uscxml::DataModelExtension DataModelExtension; +typedef uscxml::ExecutableContent ExecutableContent; +typedef uscxml::InvokerImpl InvokerImpl; +typedef uscxml::IOProcessorImpl IOProcessorImpl; +typedef uscxml::DataModelImpl DataModelImpl; +typedef uscxml::ExecutableContentImpl ExecutableContentImpl; +typedef uscxml::InterpreterIssue InterpreterIssue; + +%feature("director") uscxml::WrappedInvoker; +%feature("director") uscxml::WrappedDataModel; +%feature("director") uscxml::WrappedDataModelExtension; +%feature("director") uscxml::WrappedIOProcessor; +%feature("director") uscxml::WrappedExecutableContent; +%feature("director") uscxml::WrappedInterpreterMonitor; + +// disable warning related to unknown base class +#pragma SWIG nowarn=401 +// do not warn when we override symbols via extend +#pragma SWIG nowarn=302 +// do not warn when ignoring overrided method +#pragma SWIG nowarn=516 + +%rename(equals) operator==; // signature is wrong, still useful +%rename(isValid) operator bool; + +//************************************************** +// This ends up in the generated wrapper code +//************************************************** + +%{ + +#include "uscxml/config.h" +#include "../../../uscxml/Interpreter.h" +#include "../../../uscxml/debug/InterpreterIssue.h" +#include "../../../uscxml/interpreter/InterpreterState.h" +#include "../../../uscxml/interpreter/InterpreterMonitor.h" + +#include "../../../uscxml/messages/Data.h" +#include "../../../uscxml/messages/Event.h" +#include "../../../uscxml/util/DOM.h" + +#include "../../../uscxml/plugins/Factory.h" +#include "../../../uscxml/plugins/DataModelImpl.h" + +#include "../wrapped/WrappedInvoker.h" +#include "../wrapped/WrappedDataModel.h" +#include "../wrapped/WrappedActionLanguage.h" +#include "../wrapped/WrappedExecutableContent.h" +#include "../wrapped/WrappedIOProcessor.h" +#include "../wrapped/WrappedInterpreterMonitor.h" + +using namespace uscxml; +using namespace XERCESC_NS; + +// the wrapped* C++ classes get rid of DOM nodes and provide more easily wrapped base classes +#include "../wrapped/WrappedInvoker.cpp" +#include "../wrapped/WrappedDataModel.cpp" +#include "../wrapped/WrappedActionLanguage.cpp" +#include "../wrapped/WrappedExecutableContent.cpp" +#include "../wrapped/WrappedIOProcessor.cpp" +#include "../wrapped/WrappedInterpreterMonitor.cpp" + +%} + +%include "../uscxml_ignores.i" + +// bytearray for Blob::data +// see: http://stackoverflow.com/questions/9934059/swig-technique-to-wrap-unsigned-binary-data + +#if 0 +%apply (char *STRING, size_t LENGTH) { (const char* data, size_t size) }; + +%typemap(jni) char* getData "jbyteArray" +%typemap(jtype) char* getData "byte[]" +%typemap(jstype) char* getData "byte[]" +%typemap(javaout) char* getData { + return $jnicall; +} + +%typemap(out) char* getData { + $result = JCALL1(NewByteArray, jenv, ((uscxml::Blob const *)arg1)->getSize()); + JCALL4(SetByteArrayRegion, jenv, $result, 0, ((uscxml::Blob const *)arg1)->getSize(), (jbyte *)$1); +} +#endif + +//*********************************************** +// Beautify important classes +//*********************************************** + + +%include "../uscxml_beautify.i" + + +//*********************************************** +// Parse the header file to generate wrappers +//*********************************************** + +%include "../../../uscxml/Common.h" +%include "../../../uscxml/messages/Blob.h" +%include "../../../uscxml/messages/Data.h" +%include "../../../uscxml/messages/Event.h" + +%include "../../../uscxml/plugins/Factory.h" +%include "../../../uscxml/interpreter/InterpreterState.h" +%include "../../../uscxml/interpreter/InterpreterMonitor.h" + +//%include "../../../uscxml/interpreter/MicroStep.h" +//%include "../../../uscxml/interpreter/ContentExecutor.h" + +%include "../../../uscxml/Interpreter.h" +%include "../../../uscxml/debug/InterpreterIssue.h" + +%include "../../../uscxml/plugins/EventHandler.h" + +%include "../../../uscxml/plugins/DataModel.h" +%include "../../../uscxml/plugins/DataModelImpl.h" +%include "../../../uscxml/plugins/ExecutableContent.h" +%include "../../../uscxml/plugins/ExecutableContentImpl.h" +%include "../../../uscxml/plugins/Invoker.h" +%include "../../../uscxml/plugins/InvokerImpl.h" +%include "../../../uscxml/plugins/IOProcessor.h" +%include "../../../uscxml/plugins/IOProcessorImpl.h" + +%include "../wrapped/WrappedInvoker.h" +%include "../wrapped/WrappedDataModel.h" +%include "../wrapped/WrappedActionLanguage.h" +%include "../wrapped/WrappedExecutableContent.h" +%include "../wrapped/WrappedIOProcessor.h" +%include "../wrapped/WrappedInterpreterMonitor.h" + + +%template(IssueList) std::list; +%template(DataList) std::list; +%template(DataMap) std::map; +%template(StringSet) std::set; +%template(StringVector) std::vector; +%template(StringList) std::list; +%template(ParamMap) std::map >; +%template(IOProcMap) std::map; +%template(InvokerMap) std::map; -- cgit v0.12