Modul:Sandlådan/SM5POR/Adapt
Dokumentation [visa] [redigera] [historik] [rensa sidcachen]
|
This page documents the development version of the Adapt module. Since it is intended for an international audience, it is written in English, even as the development currently takes place on Swedish Wikipedia. |
Introduction[redigera wikitext]
The Adapt module provides utilities to simplify development and testing of other modules.
Basic concepts[redigera wikitext]
Simulated mode[redigera wikitext]
To allow testing a Lua module together with an operational systems while causing zero or minimal impact on the latter, one or more of the software interfaces may be placed in simulated mode, thereby interacting with alternative data sources or sinks. The alternative functions are provided by the calling module.
For each interface, normal operation is indicated by mode 0 (the default), while a non-zero mode indicates which alternative function is used for simulation. There can be any number of alternative functions available, but only one function may be selected per interface at the same time.
Technical reference[redigera wikitext]
Exported functions[redigera wikitext]
call[redigera wikitext]
def[redigera wikitext]
sim[redigera wikitext]
Code samples[redigera wikitext]
See also[redigera wikitext]
License[redigera wikitext]
-- The Adapt module (adaptation layer)
local interface = {}
-- Exported functions and variables follow
local adapt = {}
adapt.def = function(ift)
interface = {}
local k, v
local i = 0
for k, v in pairs(ift) do
interface[i] = v
i = i + 1
end
return nil
end
adapt.call = function(cif, par)
return interface[cif](par)
end
adapt.sim = function(sim)
local k, v
local i = 0
for k, v in pairs(sim) do
interface[i] = v
end
return sim
end
return adapt