Skip to main content

Snippet Creation

Create

Typically, a snippet template .snippet should directly return a table, for example:

return {
name = 'Test snippet'; -- snippet name
description = 'Used to test various pickers'; -- snippet description
arguments = { -- picker list
{ -- picker 1
type = 'app'; -- picker type
title = 'Select App'; -- picker title
subtitle = 'Please select an app'; -- picker subtitle
default = 'com.xxtouch.XXTExplorer'; -- default value
},
{ -- picker 2
type = 'loc';
title = 'Select Location';
subtitle = 'Pick any location you like';
default = xui.get('com.darwindev.XXTExplorer', 'location1');
-- You can use any API supported by .xui inside a .snippet
},
{ -- picker 3

},
-- ...
};
generator = function (...) -- variadic generator
-- Process parameters and return the generated result
local result
return result
end;
}

Root level

KeyTypeDescription
namestringSnippet display name
descriptionstringSnippet description
argumentsarrayPicker list
generatorfunctionSnippet generator
outputstringStandalone output filename

name and description are shown in the file manager and the snippet entry.

arguments is an array containing one or more picker-parameter dictionaries. The app builds a picker queue in the specified order and guides the user to select step by step. After completion, the app passes the picker return values as variadic parameters to generator and returns its result.

A .snippet can be used standalone. If you want to allow standalone usage, set the output field. The text returned by generator will be saved to the file identified by output in the same directory.

Picker parameter dictionary

KeyTypeDescription
typestringPicker type
titlestringPicker title (shown below the picker)
subtitlestringPicker subtitle (shown below the picker)
defaultprimitiveDefault value

See later sections for details about each picker type’s parameter dictionary.

Use in XUI

If a .snippet is used in the XUI TitleValue component, you can launch the picker queue from XUI and save the result into the component’s preferences. The .snippet can call all XUI APIs such as xui.get/xui.set/xpp.bundle_path.

Use in the code editor

Place .snippet files into the main directory’s snippets folder to be available in the app’s code editor. Tap the star icon in the keyboard toolbar to quickly generate and insert a snippet into the code being edited.

Use as a standalone file

Set the output field and put the snippet into lua/scripts under the main directory. You can tap it in the app to start the picker queue, and the text returned by generator will be saved to the file specified by output in the same directory.