Module assetreader

Utility for reading files from Android, which are out of reach of Lua's file API.

This is a thin veneer over Android's AssetManager.

To use the plugin, add the following in build.settings:

plugins = {
   ["plugin.AssetReader"] = { publisherId = "com.xibalbastudios" }
 }

Sample code is available here.

This plugin is designed to be called safely from other Lua processes.

Functions

EnumerateDirectory (path[, into]) Gather the contents of assets or one of its subdirectories.
NewProxy () Create a proxy that may be bound to an asset.
Read (filename) If a file is found in the assets, extract its content.
Proxy:Bind (filename[, opts]) If a file is found in the assets, clear the proxy and bind the asset.
Proxy:Clear () Remove any resources associated with the proxy.
Proxy:GetRemainingLength ()


Functions

EnumerateDirectory (path[, into])
Gather the contents of assets or one of its subdirectories.

Parameters:

  • path string Path to directory, relative to assets, the top-level being "".
  • into table If provided, this will be populated and returned. Otherwise, a new table is created. (optional)

Returns:

  1. {string,...} List of file and / or directory names.
  2. uint Number of entries in the directory. If into was provided, any of its entries not overwritten will be left as-is, so the simpler #into is unreliable.

Or

    nil, indicating an empty or missing directory.
NewProxy ()
Create a proxy that may be bound to an asset.

Proxies implement ByteReader, allowing them to be consumed elsewhere.

Returns:

    Proxy
Read (filename)
If a file is found in the assets, extract its content.

Parameters:

Returns:

    string or nil On success, the content bytes; otherwise nil.
Proxy:Bind (filename[, opts])
If a file is found in the assets, clear the proxy and bind the asset.

Parameters:

  • filename string
  • opts table

    Bind options, which include:

    • chunk_size: Size of reads, ≤ 1MB. (Not yet implemented)
    • mode: Read mode. (Not yet implemented)
    (optional)

Returns:

    boolean Was the asset bound?
Proxy:Clear ()
Remove any resources associated with the proxy.
Proxy:GetRemainingLength ()

Returns:

    uint Number of bytes left to read from the asset, ≤ its size, or 0 if clear.
generated by LDoc 1.4.6 Last updated 2018-07-05 18:08:55