Native dialogs library


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.


  1. Add the library as a dependency in your Defold project. Pick one of the release Zip file URLs from:

  2. 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…)

  3. In one of your scripts, add; local dialogs = require "dialogs/dialogs".

  4. When you want to show a dialog, call:

    • “Open file”-dialog:
    print(".txt,.lua", "c:/PathToDefaultDirectory"))
    • “Save file”-dialog:
    print(".txt,.lua", "c:/PathToDefaultDirectory"))





You can make a file dialog for windows x64

				comm = '"'..string.sub(pathWithFilename, 1,-2)..'\\test.bat"' 
                                --execute bat file calling file dialog
                               --bat save link file to "\tx.dt"
				f = (, 1,-2)..'\\tx.dt',"r"))
				file_path = (f:read())
				-- file_path contains a link to a file

the contents of the bat file:
@echo off
SetLocal EnableExtensions

for /f “tokens=2 delims=:” %%i in (‘chcp’) do set sPrevCP=%%i& chcp 1251 >nul
for /f “usebackq delims=” %%i in (mshta.exe "about:<input type=file id=F><script>;new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(F.value);close();</script>" ^|more) do (
set file=%%i
chcp %sPrevCP% >nul
if defined file (
echo %file%>tx.dt