# Native dialogs library

**URL:** <https://forum.defold.com/t/native-dialogs-library/3738>\
**Category:** The Defoldmine\
**Created:** [December 19, 2016, 11:37pm UTC](https://forum.defold.com/t/native-dialogs-library/3738 "2016-12-19T23:37:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [December 19, 2016, 11:37pm UTC](https://forum.defold.com/t/native-dialogs-library/3738/1 "2016-12-19T23:37:09Z")

</div>

We are all eagerly awaiting the arrival of native extensions, but there is still some room for hacking using [LuaJit FFI](http://luajit.org/ext_ffi.html) 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`](https://github.com/andsve/defold-dialogs).

**Important:** It uses the FFI module in LuaJit, thus not available on all platforms. Currently only Windows (32bit) and OSX works.

**Usage:**

1. Add the library as a [dependency](http://www.defold.com/manuals/libraries/#_setting_up_library_dependencies) in your Defold project. Pick one of the release Zip file URLs from: [Releases · andsve/defold-dialogs · GitHub](https://github.com/andsve/defold-dialogs/releases)

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:

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [December 20, 2016, 7:41am UTC](https://forum.defold.com/t/native-dialogs-library/3738/2 "2016-12-20T07:41:33Z")

</div>

![Genius](https://defold-forum-bucket.nbg1.your-objectstorage.com/original/2X/1/10491c8745ac4b1c0ea71fd2cd9bf01e95096135.gif)

---

<div class="post-metadata">

**Author:** ![gritsaenkosergeia](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gritsaenkosergeia/32/8106_2.png) [@gritsaenkosergeia](https://forum.defold.com/u/gritsaenkosergeia)\
**Post date:** [August 22, 2019, 5:11am UTC](https://forum.defold.com/t/native-dialogs-library/3738/3 "2019-08-22T05:11:32Z")

</div>

You can make a file dialog for windows x64

```lua
				pathWithFilename=io.popen("cd"):read'*all'
				comm = '"'..string.sub(pathWithFilename, 1,-2)..'\\test.bat"' 
                                --execute bat file calling file dialog
				os.execute(comm)
                               --bat save link file to "\tx.dt"
				f = (io.open(string.sub(pathWithFilename, 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>F.click();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  
)
