Storage module
Storage module description
Module provides an access to persistent storage. Plugins can store data in key/value format. Each plugin has its own volume in storage and implementation must guarantee no clashes between key's in different volume's As long as one plugin can use other ones and so on forming calling tree an implementation must use volume for the root plugin in this tree. It means that if plugin is meant to be used as library it will have separate storage for every topmost user. However, plugins in one calling tree should take responsibility to prevent key collision in one volume.
Storage module API (require "storage"
)
get_bool( key )
, get_number( key )
, get_string( key )
,
get_table( key )
Get value from storage with corresponding key.
call storage.get_***( key )
params: key - string
return: value if it exists and can be converted to specified type,
nil
otherwise
example
require "storage"
local val = storage.get_number("Pi")
set_bool( key, value )
, set_number( key, value )
,
set_string( key, value )
, set_table( key, value )
Put value to storage with corresponding key
call storage.set_***( key, value )
params: key - string, value - accordingly to method name
return: none
example
require "storage"
storage.set_number("Pi", 3.1415)
exists( key )
Check if key is set.
call storage.exists( key )
params: key - string
return:
true
if key is set,false
otherwise
example
require "storage"
if storage.exists("Pi") then
print("Pi is stored")
else
print("Pi is not stored")
end
delete( key )
Delete value from storage marked with key. Function has no effect if key does not exist.
call storage.delete( key )
params: key - string
return: none
example
require "storage"
storage.delete("Pi")
delete_all()
Clear storage. Deletes all key/value pairs from current volume
call storage.delete_all()
params: none
return: none
example
require "storage"
storage.delete_all()