Native extensions allows you to create plugins to the engine, using the Lua interface, native code and also functionality Defold provides via the Defold SDK.
The defold sdk contains public headers and libraries from the engine. The internal structure of the sdk's are matching the structure in the DYNAMO_HOME folder.
E.g. (don't use these specific ones, since they might grow "old", they're simply here for copy paste reasons)
http://d.defold.com/archive/bdbf6ddaefb79c22214c86f945ea91d7fa6171de/engine/defoldsdk.zip http://d.defold.com/archive/bdbf6ddaefb79c22214c86f945ea91d7fa6171de/engine/x86_64-darwin/defoldsdk.zip
The sdk is built, packaged and uploaded for each platform during the build_engine step in build.py. And when the archive_engine step is run, all platform sdk's are downloaded and merged into one zip file.
You can build each platform individually:
defold$ ./scripts/build.py build_platform_sdk --platform=x86_64-darwin
An important part of the sdk is the defold/share/extender/build.yml which controls the compiler settings for the server. As we include this file in every sdk, we make it simple to update. You can update it simply by running:
$ waf install
Note that during the development of the SDK, you can run the local server, pointing it to your DYNAMO_HOME variable! This of course requires you to have build the engine beforehand:
defold$ ./scripts/build.py build_engine --platform=x86_64-darwin
Set up the path for the DYNAMO_HOME variable:
export DYNAMO_HOME=/Users/mathiaswesterdahl/work/defold/tmp/dynamo_home
To use Editor 1 against the production extender service, you need to specify -Ddefold.sha1=<SHA1>
as one of the run arguments for the editor. <SHA1>
should be set to a commit hash that has been built on CI (since this is where the SDK is built and uploaded).
There are two ways of launching a local server, via gradle or docker. Both require the same git repository, and both respect the DYNAMO_HOME environment variable.
The local server can be built and started using the defold/extender repository.
$ git clone https://github.com/defold/extender.git
To launch the server locally, via gradle:
$ cd extender
extender$ ./gradlew build
extender$ ./gradlew bootRun
The easiest way to debug is to use the docker container. First, install Docker
The gradle server also runs inside a docker container:
$ cd extender
extender$ ./scripts/build.sh
extender$ ./scripts/run.sh
It's quite easy to get access to your docker container:
extender$ ./scipts/debug.sh
The native extensions are only supported via Editor 2.
The setup steps are described here
editor$ lein run
In the preferences, select "Enable Native Extensions"
The project layout is quite straight forward. Here's a simple example
VideoPlayer
main
...
include
mylib.h
lib
x86_64-osx
libmylib.a
src
myluamodule.cpp
- Don't put headers in the src/ folder! They currently get built as .cpp files
Simply build with Command/Ctrl + B Any build errors will show up in the Editor 2 console.
Currently, the downloaded (built) engine, is created as a temporary file. This makes it very hard to debug.