Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added example with mocml generation

  • Loading branch information...
commit 2116dc4b745055b67e9c2ed4b85a38339dfa6b78 1 parent 167e6d2
@Kakadu authored
View
2  qml/test2/.gitignore
@@ -0,0 +1,2 @@
+main
+test1.creator.user
View
1  qml/test2/Gamemap.cpp
@@ -0,0 +1 @@
+#include "Gamemap.h"
View
51 qml/test2/Gamemap.h
@@ -0,0 +1,51 @@
+#ifndef Gamemap_H
+#define Gamemap_H
+
+#include <QObject>
+#include <QDebug>
+#include <kamlo.h>
+
+class Gamemap : public QObject {
+ Q_OBJECT
+public:
+public:
+ Q_PROPERTY(QString title WRITE setTitle READ title NOTIFY titleChanged)
+ QString title() {
+ value *closure = caml_named_value("prop_Gamemap_title_get");
+ Q_ASSERT_X(closure!=NULL,"Gamemap::title","ocaml's closure `prop_Gamemap_title_get` not found");
+ value _ans = caml_callback(*closure, Val_unit);
+ return QString(String_val(_ans));
+ }
+ void setTitle(QString x0) {
+ value *closure = caml_named_value("prop_Gamemap_setTitle_set");
+ Q_ASSERT_X(closure!=NULL,"Gamemap::setTitle","ocaml's closure `prop_Gamemap_setTitle_set` not found");
+ value *args = new value[1];
+ args[0] = caml_copy_string(x0.toLocal8Bit().data() );
+ // delete args or not?
+ caml_callbackN(*closure, 1, args);
+ }
+signals:
+ void titleChanged();
+public:
+ Q_PROPERTY(int width WRITE setWidth READ width NOTIFY widthChanged)
+ int width() {
+ value *closure = caml_named_value("prop_Gamemap_width_get");
+ Q_ASSERT_X(closure!=NULL,"Gamemap::width","ocaml's closure `prop_Gamemap_width_get` not found");
+ int _ans = caml_callback(*closure, Val_unit);
+ return Int_val(_ans);
+ }
+ void setWidth(int x0) {
+ value *closure = caml_named_value("prop_Gamemap_setWidth_set");
+ Q_ASSERT_X(closure!=NULL,"Gamemap::setWidth","ocaml's closure `prop_Gamemap_setWidth_set` not found");
+ value *args = new value[1];
+ args[0] = Val_int (x0);
+ // delete args or not?
+ caml_callbackN(*closure, 1, args);
+ }
+signals:
+ void widthChanged();
+public:
+ explicit Gamemap(QObject *parent = 0) : QObject(parent) {}
+};
+#endif
+
View
35 qml/test2/Makefile
@@ -0,0 +1,35 @@
+qtgcc=g++ -g `pkg-config --cflags QtDeclarative` -I`ocamlfind c -where`
+asdf=-c -m64 -pipe -g -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_DECLARATIVE_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtDeclarative -I/usr/include/qt4 -I.
+
+mocs=moc_Gamemap.cpp
+cppobjs=Gamemap.o moc_Gamemap.o main.o
+mlobjs=stubs.o
+ocamlobjs=ocaml/camlcode.o
+out=main
+-include $(shell ocamlc -where)/Makefile.config
+
+.SUFFIXES: .cpp .h .o
+
+.PHONY: all kamlo
+
+all: gencode $(mocs) $(cppobjs) kamlo
+ $(qtgcc) $(cppobjs) $(ocamlobjs) `pkg-config --libs QtDeclarative` \
+ -L"`ocamlfind c -where`" $(NATIVECCLIBS) -lasmrun \
+ -o $(out)
+
+gencode:
+ ./mocml
+ echo "=)"
+
+kamlo:
+ $(MAKE) -C ocaml
+
+moc_%.cpp: %.h
+ moc $< > $@
+
+.cpp.o:
+ $(qtgcc) -c $< -I.
+
+clean:
+ rm moc_* *.o $(out) -f
+ $(MAKE) -s --no-print-directory -C ocaml clean
View
16 qml/test2/input_yaml
@@ -0,0 +1,16 @@
+---
+Gamemap:
+ properties:
+ title:
+ type: string
+ name: title
+ set: setTitle
+ get: title
+ notify: titleChanged
+ width:
+ type: int
+ name: width
+ set: setWidth
+ get: width
+ notify: widthChanged
+
View
22 qml/test2/kamlo.h
@@ -0,0 +1,22 @@
+#ifndef KAMLO_H
+#define KAMLO_H
+
+extern "C" {
+#include <caml/mlvalues.h>
+#include <caml/alloc.h>
+#include <caml/memory.h>
+#include <caml/callback.h>
+
+}
+
+#define Val_none Val_int(0)
+static inline value
+Some_val(value v) {
+ CAMLparam1(v);
+ CAMLlocal1(ans);
+ ans = caml_alloc_small(1,0);
+ Field(ans,0)=v;
+ CAMLreturn(ans);
+}
+
+#endif
View
16 qml/test2/main.cpp
@@ -0,0 +1,16 @@
+#include <QtGui/QApplication>
+#include <QDeclarativeContext>
+#include "Gamemap.h"
+#include <QtDeclarative/QDeclarativeView>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ caml_main(argv);
+ QDeclarativeView viewer;
+ Gamemap map;
+ viewer.rootContext() -> setContextProperty("gameMap",&map);
+ viewer.setSource(QUrl("qml/main.qml"));
+ viewer.show();
+ return app.exec();
+}
View
1  qml/test2/mocml
View
2  qml/test2/ocaml/.gitignore
@@ -0,0 +1,2 @@
+*.cm[ioax]
+
View
7 qml/test2/ocaml/Makefile
@@ -0,0 +1,7 @@
+all:
+ ocamlfind opt -c code.ml
+ ocamlfind opt -output-obj -o camlcode.o code.cmx
+
+clean:
+ rm *.o *.cmx -f
+
View
17 qml/test2/ocaml/code.ml
@@ -0,0 +1,17 @@
+let gamemap = object
+ val mutable title = "mytitle"
+ method title () = title
+ method setTitle s = title <- s
+ val mutable width = 640
+ method width () = width
+ method setWidth s = width <- s
+
+end
+
+let () = Callback.register "prop_Gamemap_title_get" gamemap#title
+let () = Callback.register "prop_Gamemap_title_set" gamemap#setTitle
+
+let () = Callback.register "prop_Gamemap_width_get" gamemap#width
+let () = Callback.register "prop_Gamemap_width_set" gamemap#setWidth
+
+
View
10 qml/test2/qml/main.qml
@@ -0,0 +1,10 @@
+import QtQuick 1.0
+
+Rectangle {
+ width: gameMap.width;
+ height: 600;
+ Text {
+ text: gameMap.title;
+ anchors.centerIn: parent
+ }
+}
View
1  qml/test2/test2.config
@@ -0,0 +1 @@
+// ADD PREDEFINED MACROS HERE!
View
1  qml/test2/test2.creator
@@ -0,0 +1 @@
+[General]
View
142 qml/test2/test2.creator.user
@@ -0,0 +1,142 @@
+<!DOCTYPE QtCreatorProject>
+<qtcreator>
+ <data>
+ <variable>GenericProjectManager.GenericProject.Toolchain</variable>
+ <value type="QString">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.ActiveTarget</variable>
+ <value type="int">0</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.EditorSettings</variable>
+ <valuemap type="QVariantMap">
+ <value key="EditorConfiguration.AutoIndent" type="bool">true</value>
+ <value key="EditorConfiguration.AutoSpacesForTabs" type="bool">true</value>
+ <value key="EditorConfiguration.Codec" type="QByteArray">UTF-8</value>
+ <value key="EditorConfiguration.DoubleIndentBlocks" type="bool">false</value>
+ <value key="EditorConfiguration.IndentBraces" type="bool">false</value>
+ <value key="EditorConfiguration.IndentSize" type="int">4</value>
+ <value key="EditorConfiguration.MouseNavigation" type="bool">true</value>
+ <value key="EditorConfiguration.PaddingMode" type="int">1</value>
+ <value key="EditorConfiguration.ScrollWheelZooming" type="bool">true</value>
+ <value key="EditorConfiguration.SmartBackspace" type="bool">true</value>
+ <value key="EditorConfiguration.SpacesForTabs" type="bool">true</value>
+ <value key="EditorConfiguration.TabKeyBehavior" type="int">0</value>
+ <value key="EditorConfiguration.TabSize" type="int">4</value>
+ <value key="EditorConfiguration.UseGlobal" type="bool">true</value>
+ <value key="EditorConfiguration.Utf8BomBehavior" type="int">1</value>
+ <value key="EditorConfiguration.addFinalNewLine" type="bool">true</value>
+ <value key="EditorConfiguration.cleanIndentation" type="bool">true</value>
+ <value key="EditorConfiguration.cleanWhitespace" type="bool">true</value>
+ <value key="EditorConfiguration.inEntireDocument" type="bool">true</value>
+ </valuemap>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Target.0</variable>
+ <valuemap type="QVariantMap">
+ <value key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName" type="QString">Desktop</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString"></value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">GenericProjectManager.GenericTarget</value>
+ <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">0</value>
+ <value key="ProjectExplorer.Target.ActiveDeployConfiguration" type="int">0</value>
+ <value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
+ <valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
+ <value key="GenericProjectManager.GenericBuildConfiguration.BuildDirectory" type="QString">/home/kakadu/mand/prog/lablqt/qml/test2</value>
+ <value key="ProjectExplorer.BuildCOnfiguration.ToolChain" type="QString">INVALID</value>
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStepList.0" type="QVariantMap">
+ <valuemap key="ProjectExplorer.BuildStepList.Step.0" type="QVariantMap">
+ <valuelist key="GenericProjectManager.GenericMakeStep.BuildTargets" type="QVariantList">
+ <value type="QString">all</value>
+ </valuelist>
+ <value key="GenericProjectManager.GenericMakeStep.MakeArguments" type="QString"></value>
+ <value key="GenericProjectManager.GenericMakeStep.MakeCommand" type="QString"></value>
+ <value key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName" type="QString">Make</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString"></value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">GenericProjectManager.GenericMakeStep</value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildStepList.StepsCount" type="int">1</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName" type="QString">Build</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString"></value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">ProjectExplorer.BuildSteps.Build</value>
+ </valuemap>
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStepList.1" type="QVariantMap">
+ <value key="ProjectExplorer.BuildStepList.StepsCount" type="int">0</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName" type="QString">Clean</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString"></value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">ProjectExplorer.BuildSteps.Clean</value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.BuildStepListCount" type="int">2</value>
+ <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
+ <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ <value key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName" type="QString"></value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">all</value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">GenericProjectManager.GenericBuildConfiguration</value>
+ </valuemap>
+ <value key="ProjectExplorer.Target.BuildConfigurationCount" type="int">1</value>
+ <valuemap key="ProjectExplorer.Target.DeployConfiguration.0" type="QVariantMap">
+ <valuemap key="ProjectExplorer.BuildConfiguration.BuildStepList.0" type="QVariantMap">
+ <value key="ProjectExplorer.BuildStepList.StepsCount" type="int">0</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName" type="QString">Deploy</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString"></value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">ProjectExplorer.BuildSteps.Deploy</value>
+ </valuemap>
+ <value key="ProjectExplorer.BuildConfiguration.BuildStepListCount" type="int">1</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName" type="QString">No deployment</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString"></value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">ProjectExplorer.DefaultDeployConfiguration</value>
+ </valuemap>
+ <value key="ProjectExplorer.Target.DeployConfigurationCount" type="int">1</value>
+ <valuemap key="ProjectExplorer.Target.RunConfiguration.0" type="QVariantMap">
+ <valuelist key="Analyzer.Valgrind.AddedSupressionFiles" type="QVariantList"/>
+ <value key="Analyzer.Valgrind.FilterExternalIssues" type="bool">true</value>
+ <value key="Analyzer.Valgrind.NumCallers" type="int">25</value>
+ <valuelist key="Analyzer.Valgrind.RemovedSupressionFiles" type="QVariantList"/>
+ <value key="Analyzer.Valgrind.TrackOrigins" type="bool">true</value>
+ <value key="Analyzer.Valgrind.ValgrindExecutable" type="QString">valgrind</value>
+ <valuelist key="Analyzer.Valgrind.VisibleErrorKinds" type="QVariantList">
+ <value type="int">0</value>
+ <value type="int">1</value>
+ <value type="int">2</value>
+ <value type="int">3</value>
+ <value type="int">4</value>
+ <value type="int">5</value>
+ <value type="int">6</value>
+ <value type="int">7</value>
+ <value type="int">8</value>
+ <value type="int">9</value>
+ <value type="int">10</value>
+ <value type="int">11</value>
+ <value type="int">12</value>
+ <value type="int">13</value>
+ <value type="int">14</value>
+ </valuelist>
+ <value key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments" type="QString"></value>
+ <value key="ProjectExplorer.CustomExecutableRunConfiguration.BaseEnvironmentBase" type="int">2</value>
+ <value key="ProjectExplorer.CustomExecutableRunConfiguration.Executable" type="QString"></value>
+ <value key="ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal" type="bool">false</value>
+ <valuelist key="ProjectExplorer.CustomExecutableRunConfiguration.UserEnvironmentChanges" type="QVariantList"/>
+ <value key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory" type="QString">%{buildDir}</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName" type="QString">Custom Executable</value>
+ <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString"></value>
+ <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">ProjectExplorer.CustomExecutableRunConfiguration</value>
+ <value key="RunConfiguration.QmlDebugServerPort" type="uint">3768</value>
+ <value key="RunConfiguration.UseCppDebugger" type="bool">true</value>
+ <value key="RunConfiguration.UseQmlDebugger" type="bool">false</value>
+ </valuemap>
+ <value key="ProjectExplorer.Target.RunConfigurationCount" type="int">1</value>
+ </valuemap>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.TargetCount</variable>
+ <value type="int">1</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
+ <value type="QString">{a0bdfb90-c06c-44b4-bb87-c358218a71b2}</value>
+ </data>
+ <data>
+ <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
+ <value type="int">9</value>
+ </data>
+</qtcreator>
View
7 qml/test2/test2.files
@@ -0,0 +1,7 @@
+Gamemap.cpp
+Gamemap.h
+main.cpp
+kamlo.h
+Makefile
+ocaml/code.ml
+qml/main.qml
View
8 qml/test2/test2.includes
@@ -0,0 +1,8 @@
+ocaml
+qml
+/usr/include/qt4
+/usr/include/
+/usr/include/qt4/QtCore
+/usr/include/qt4/Qt
+/usr/include/qt4/QtDeclarative
+/usr/lib/ocaml/caml
Please sign in to comment.
Something went wrong with that request. Please try again.