Repository navigation
API
Returns whether this is an HTML5 build.
local supported = browser_io.is_supported()boolean
true on HTML5 builds and false on other build targets.
This does not test an individual browser API. Use the can_*() functions for feature detection.
Returns whether the current browser context exposes clipboard text writing.
local supported = browser_io.can_copy()The implementation requires:
- a secure browser context
navigator.clipboardnavigator.clipboard.writeText
A returned value of true means the operation can be attempted. Browser security policy can still reject the request.
Returns whether the current browser context exposes clipboard text reading.
local supported = browser_io.can_paste()The implementation requires:
- a secure browser context
navigator.clipboardnavigator.clipboard.readText
A returned value of true does not guarantee permission to read the clipboard.
Returns whether the browser exposes the APIs required by open_file().
local supported = browser_io.can_open_file()The current implementation checks for DOM element creation and FileReader.
Returns whether the browser exposes the APIs required by save_file().
local supported = browser_io.can_save_file()The current implementation checks for:
BlobURL.createObjectURL- an
<a>element with download support
Returns whether the browser exposes drag/drop and file-reading APIs.
local supported = browser_io.can_drop_files()This is an API capability check only. It does not guarantee that an external file-drag workflow is practical on a touch-only device.
Copies UTF-8 text to the system clipboard.
local request_id = browser_io.copy(text, callback)text
: Lua string containing the text to copy.
callback
: Function called as:
callback(self, result)On success:
{
success = true,
cancelled = false,
operation = "copy"
}On failure:
{
success = false,
cancelled = false,
operation = "copy",
error = "..."
}A numeric request ID.
Reads UTF-8 text from the system clipboard.
local request_id = browser_io.paste(callback){
success = true,
cancelled = false,
operation = "paste",
data = "...",
size = 123
}size is the byte length of the Lua string.
An empty successful paste returns:
data = ""
size = 0A numeric request ID.
Opens a browser file picker and reads one selected file into a Lua string.
browser_io.open_file(nil, callback)
browser_io.open_file(options, callback){
accept = ".ohm",
max_size = 16384
}Optional HTML-style accept filter.
The JavaScript bridge supports:
- file extensions such as
.txt - exact MIME types such as
application/json - wildcard MIME types such as
image/* - comma-separated combinations
Example:
accept = ".txt,.json,application/json"The default is an empty string, which does not restrict file type.
The selected file is checked against the accept rules by the extension after selection as well as being supplied to the browser file input.
Maximum file size in bytes.
Default:
16 MiB
A supplied numeric value is used only when greater than zero.
{
success = true,
cancelled = false,
operation = "open_file",
name = "level.ohm",
data = "...",
size = 2048
}The file data is binary-safe.
A zero-byte file returns:
data = ""
size = 0If the browser reports that the file picker was cancelled:
result.cancelled == trueA numeric request ID.
Creates a browser download from a Lua string.
browser_io.save_file(filename, data, nil, callback)
browser_io.save_file(filename, data, options, callback)filename
: Suggested download filename.
data
: Lua string containing the file bytes. Binary data is supported.
options
: Optional table.
callback
: Completion callback.
{
mime_type = "text/plain;charset=utf-8"
}Default MIME type:
application/octet-stream
{
success = true,
cancelled = false,
operation = "save_file"
}A successful result means the extension created the Blob, triggered the browser download link, and handed the operation to the browser. The extension cannot confirm that the user eventually saved the file to disk.
A numeric request ID.
Registers a persistent drag-and-drop file listener.
The listener is installed on the browser window in capture mode so that handled file drops can suppress the browser's normal navigation behaviour.
browser_io.set_drop_listener(nil, callback)
browser_io.set_drop_listener(options, callback)The options are the same as open_file():
{
accept = ".txt",
max_size = 16384
}Default max_size is 16 MiB.
{
success = true,
cancelled = false,
operation = "drop_file",
name = "level.ohm",
data = "...",
size = 2048
}Only the first file in a drop operation is processed.
The listener remains active after a callback and can receive additional drop events.
Calling set_drop_listener() again replaces the previous Lua listener.
true when enabled on HTML5.
Returns false on unsupported build targets.
Copies UTF-8 text to the system clipboard.
local request_id = browser_io.copy(text, callback)text
: Lua string containing the text to copy.
callback
: Function called as:
function(self, result)
-- result.success
-- result.cancelled
-- result.operation
-- result.error -- present on failure when available
endOn success:
{
success = true,
cancelled = false,
operation = "copy"
}On failure:
{
success = false,
cancelled = false,
operation = "copy",
error = "..."
}A numeric request ID.
Reads UTF-8 text from the system clipboard.
local request_id = browser_io.paste(callback)function(self, result)
-- result.success
-- result.cancelled
-- result.operation
-- result.data
-- result.size
-- result.error -- present on failure when available
end{
success = true,
cancelled = false,
operation = "paste",
data = "...",
size = 123
}size is the byte length of the Lua string.
An empty successful paste returns:
data = ""
size = 0A numeric request ID.
Opens a browser file picker and reads one selected file into a Lua string.
browser_io.open_file(nil, callback)
browser_io.open_file(options, callback)function(self, result)
-- result.success
-- result.cancelled
-- result.operation
-- result.name -- present when a file result is available
-- result.data -- present on successful file read
-- result.size -- byte length of result.data
-- result.error -- present on failure when available
end{
accept = ".ohm",
max_size = 16384
}Optional HTML-style accept filter.
The JavaScript bridge supports:
- file extensions such as
.ohm - exact MIME types such as
application/json - wildcard MIME types such as
image/* - comma-separated combinations
Example:
accept = ".ohm,.json,application/json"The default is an empty string, which does not restrict file type.
The selected file is checked against the accept rules by the extension after selection as well as being supplied to the browser file input.
Maximum file size in bytes.
Default:
16 MiB
A supplied numeric value is used only when greater than zero.
{
success = true,
cancelled = false,
operation = "open_file",
name = "level.ohm",
data = "...",
size = 2048
}The file data is binary-safe.
A zero-byte file returns:
data = ""
size = 0If the browser reports that the file picker was cancelled:
result.cancelled == trueA numeric request ID.
Creates a browser download from a Lua string.
browser_io.save_file(filename, data, nil, callback)
browser_io.save_file(filename, data, options, callback)filename
: Suggested download filename.
data
: Lua string containing the file bytes. Binary data is supported.
options
: Optional table.
callback
: Completion callback, called as:
function(self, result)
-- result.success
-- result.cancelled
-- result.operation
-- result.error -- present on failure when available
end{
mime_type = "text/plain;charset=utf-8"
}Default MIME type:
application/octet-stream
{
success = true,
cancelled = false,
operation = "save_file"
}A successful result means the extension created the Blob, triggered the browser download link, and handed the operation to the browser. The extension cannot confirm that the user eventually saved the file to disk.
A numeric request ID.
Registers a persistent drag-and-drop file listener.
The listener is installed on the browser window in capture mode so that handled file drops can suppress the browser's normal navigation behaviour.
browser_io.set_drop_listener(nil, callback)
browser_io.set_drop_listener(options, callback)The callback is persistent and is invoked once for each handled file drop:
function(self, result)
-- result.success
-- result.cancelled
-- result.operation
-- result.name -- present when a file result is available
-- result.data -- present on successful file read
-- result.size -- byte length of result.data
-- result.error -- present on failure when available
endUnlike the one-shot callbacks used by copy(), paste(), open_file(), and save_file(), this callback remains registered until it is replaced, cancelled with cancel_drop_listener(), or its owning script instance becomes invalid.
The options are the same as open_file():
{
accept = ".ohm",
max_size = 16384
}Default max_size is 16 MiB.
{
success = true,
cancelled = false,
operation = "drop_file",
name = "level.ohm",
data = "...",
size = 2048
}Only the first file in a drop operation is processed.
The listener remains active after a callback and can receive additional drop events.
Calling set_drop_listener() again replaces the previous Lua listener.
true when enabled on HTML5.
Returns false on unsupported build targets.
Removes the persistent drag-and-drop listener and releases its Lua callback.
browser_io.cancel_drop_listener()It is good practice to call this from final() when leaving a screen that enabled drag and drop:
function final(self)
browser_io.cancel_drop_listener()
endNo value is returned.