Programming with Lua

yichone edited this page Dec 1, 2016 · 1 revision

How to use node module

Restart your device


How to use file module

Create a file on file system (SPIFFS)"yourFile.lua","w+")  -- if the file is not exist, create one
file.write("Input your content here")
--file.writeline("Your content here")  -- write a line

Read an existing file from file system"yourFile.lua","r")  -- Use to read the first n characters of the file
--file.readline()  -- read a line

Append something new to an existing file"yourFile.lua","a")
file.write("Your content here")

Remove file from file system


How to encode/decode with cjson module

encodeString = cjson.encode({key1=value1, key2=value2})
print(encodeString)  -- {'key1':'value1', 'key2':'value2'}
decodeResult = cjson.decode(encodeString)

How to use base64

The utils module contains some useful tools, such as base64, date tool, etc. More useful tools will be added to this module, then user can invoke them from this module.

str = "hello world";
encrypt = utils.base64_encode(str);
decrypt = utils.base64_decode(encrypt);

How to use template module


The template module is a sample to show users how to create their own module. Invoke the start and stop method to test.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.