Skip to content

Instantly share code, notes, and snippets.

@Alloyed
Last active June 23, 2016 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alloyed/f8692f68f50d96de74f1ebd8ab742995 to your computer and use it in GitHub Desktop.
Save Alloyed/f8692f68f50d96de74f1ebd8ab742995 to your computer and use it in GitHub Desktop.
path,  err = nfd.open(filter, init) -- lets you pick a single file
paths, err = nfd.openMany(filter, init) -- lets you pick multiple files
path,  err = nfd.save(filter, init) -- lets you save to a single file

where:

  • filter (string, optional): A weird DSL for filetypes you probably shouldn't emulate. it supports type subgroups (so like jpg files are "jpg,jpeg" and so on) but doesn't let you name them. defaults to all files.

  • init (string, optional): The initial path the file chooser should suggest. Normally this is a directory, but for save() you can suggest an initial filename like "/my/path/untitled.file". defaults to the working directory.

  • path can be the path the user picked, or false if the user selected cancel, or nil if there was an error. This means that if path then works for checking success but if not path then doesn't work for checking failure, so I dunno about this design choice in particular.

  • paths is the same, but instead of a path string it returns a table of path strings.

  • err is the error message if there is one. hitting cancel returns an error message, too, so assert works for prototype code (you should probably let the user cancel!).

What this doesn't support:

  • titlebar
  • save vs save as
  • Naming the type of file you want ("Image files" vs. "Sound files" etc.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment