After part1(getting started) and part2(looking at generated code) now its time to generate bindings, but before that let's generate a Docker-Image that will create a docker-image with this lib installed.
Generating additional files on the project-data you can add targets. There are multiple targets to choose from:
Add a <target name="[target-name]"/>-tag to the project and just regenerate.
- So let's add the target-tag AND we need to specify a repository-attribute in project so the docker image knows where to pickup the source. (Afaik, for dockerimage to work you need a repositiory and there is no other way to pass the current source into it)
- We also remove the private-attribute for the starter-executable to be installed on 'make install'
<project script = "zproject.gsl" repository = "https://github.com/dertom95/zproject-tutorial.git" name = "gs"> <version major = "1" minor = "1" patch = "0" /> <class name = "shouter"/> <main name = "starter" private = "1" /> <target name="docker"/> </project>
This will generate the new docker-specific file(s):
Caution: Our project will generate an invalid Dockerfile due to our project not 'using' any project dependencies which seem to result in an empty 'apt-get' call in Line6. Comment this line.
To build an image with the name 'zimage' (I assume docker to be available and the current use to be in the docker-group):
docker build -t zimage .
you can run the starter-executable:
docker run zimage starter -h
if you want to see what's going on in the docker image and you want to hop into it:
docker run -it zimage /bin/bash
For the python-generator to work, we need to add a license file first (because the generator assumes this), but it is a good idea and we should have done this in the first place....
Let's copy an MIT-License and save it as license.xml:
Change your project.xml like this:
The effect will be that newly generated files add this license on top of the file. (would have been neat to work on class-headers after(!) creation as well)
In line 4 we changed the library name from 'gs' to 'zprotut' to avoid library name clashes...(seems like there is a libgs already, my bad 😉)
In line 13 we added the python-target which will add a folder 'bindings/python'.
Due to the lib-name changed remove all file and folders with prefix gs_ and generate:
build the the library again and go to the build-folder where you can find the shared-libraries and write:
This will temporarily add this folder to the library search path and make it available for the python-binding.
cd bindings/python/ python setup.py build python setup.py install
Notice: I'm not that confident with the best ways to manually install python-libraries. I guess you should create a virtual-environment and I guess 'python setup.py install' would have been enough...
With the shared-library in LD-Path and the python lib installed you can go on a python shell and execute following:
# import our class from zprotut import Shouter # create an instance. string-types need to be add as bytes with b-prefix shouter = Shouter(b"abc") # call the instance shouter.shout_multi(b"forty",3)
That concludes part3 and finish the 'getting started'-guide. There is so much to explore. e.g. in the API-Model 'callbacks' or 'actors'.
Have fun with this project.