jp-embedded / scxmlcc

The SCXML state machine to C++ compiler
GNU General Public License v3.0
140 stars 34 forks source link

Add user includes to generated code #78

Closed sstiller closed 5 years ago

sstiller commented 5 years ago

It's nice if you want to use something from different libraries in <script> or add user defined data types to the data model. This PR may close #63

jp-embedded commented 5 years ago

I would really prefer to have these includes embedded in the scxml file to make them self contained and not depend on specific parameters

An example of what I had in mind regarding this:

<scxml initial="hello" version="0.9" xmlns="http://www.w3.org/2005/07/scxml">
 <script>
  #include "someheader.h"
  bool some_helper_func() { ... }
 </script>
 <state id="hello">
  <transition target="world"></transition>
 </state>
 <state id="world"></state>
</scxml>

This would give the greatest flexibility.

This might be pushing the standard a bit, depending on how you define 'load time' in a compiled SM:

The SCXML Processor must evaluate any <script> element that is a child of <scxml> at document load time. It must evaluate all other <script> elements as part of normal executable content evaluation.

Another way could be the 'Qt' way: https://doc.qt.io/qt-5.11/qtscxml-mediaplayer-qml-cppdatamodel-mediaplayer-cppdatamodel-scxml.html, but this is much more strict.

sstiller commented 5 years ago

You are right, it would be great do add the #include into the scxml. I don't like the Qt version, your example is much more obvious.

ringlej commented 5 years ago

My interpretation of 'document load time' fits this. For a compiled SM, the 'document load time' is at the time in which it was compiled :)