We are all eagerly awaiting the arrival of native extensions, but there is still some room for hacking using LuaJit FFI in the mean time, at least on desktop.
While working on a pet project I needed access to “Save/Open file”-dialogs, something currently not exposed in the Defold API. This prompted me to hack together a dumb little library called; defold-dialogs
.
Important: It uses the FFI module in LuaJit, thus not available on all platforms. Currently only Windows (32bit) and OSX works.
Usage:
-
Add the library as a dependency in your Defold project. Pick one of the release Zip file URLs from: https://github.com/andsve/defold-dialogs/releases
-
Currently you need to copy the
native_libs
folder supplied in the library to the root of your project. (I’m trying to figure out ways to skip this…) -
In one of your scripts, add;
local dialogs = require "dialogs/dialogs"
. -
When you want to show a dialog, call:
- “Open file”-dialog:
print(dialogs.open(".txt,.lua", "c:/PathToDefaultDirectory"))
- “Save file”-dialog:
print(dialogs.save(".txt,.lua", "c:/PathToDefaultDirectory"))