Module utils.loader

Code loading/unloading utils.

This module provides additional utility functions to handle the lifecycle of Lua files.

Type utils.loader

utils.loader.loadBuffer(buffer, name, destroy)

Compiles a buffer (ie a list of strings) into an executable function.

utils.loader.unload(name)

Unloads a module by removing references to it.

Type utils.loader

Field(s)

utils.loader.loadBuffer(buffer, name, destroy)

Compiles a buffer (ie a list of strings) into an executable function.

This function is quite similar to Lua's loadstring() core function, except that it takes a list of strings as a parameter rather than a single string. Since it never concatenates the string internally, using this function instead of loadstring() limit fragmentation issues when loading large files on a device with very limited RAM resources.

Parameters

  • buffer : a list of strings.

  • name : is an optional chunk name used for debug traces.

  • destroy : is a boolean. When true, the buffer is read destructively (saves RAM when handling big sources).

Return value

function resulting of the buffer compilation

utils.loader.unload(name)

Unloads a module by removing references to it.

When a module isn't used anymore, one can call this function with the module's name as a parameter. It will remove references to the module in package's internal tables, thus allowing the module's resources to be reclaimed by the garbage collector if no deangling references remain in the application.

  1. Call function package.loaded[name].__unload() if it exists
  2. Clear package.loaded[name]
  3. Clear _G[name]

Parameter

  • name : the name of the module to unload.