Skip to content

Commit fd968c2

Browse files
author
SICKAppSpace-dev
committed
Update
1 parent e768cfd commit fd968c2

File tree

4 files changed

+71
-69
lines changed

4 files changed

+71
-69
lines changed

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2222
OTHER DEALINGS IN THE SOFTWARE.
2323

2424
For more information, please refer to <https://unlicense.org>
25+

StringStreaming/project.mf.xml

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<manifest>
3-
<application name="StringStreaming">
4-
<crown name="StringStreaming">
5-
<desc>user script</desc>
6-
</crown>
7-
<meta key="author">AppSpace Sample</meta>
8-
<meta key="version">2.5.0</meta>
9-
<meta key="licensed">false</meta>
10-
<meta key="priority">low</meta>
11-
<meta key="copy-protected">false</meta>
12-
<meta key="read-protected">false</meta>
13-
<meta key="tags">Lua</meta>
14-
<entry path="scripts" default="StringStreaming.lua">
15-
<file type="text/x-lua">StringStreaming.lua</file>
16-
</entry>
17-
</application>
18-
</manifest>
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<manifest>
3+
<application name="StringStreaming">
4+
<crown name="StringStreaming">
5+
<desc>user script</desc>
6+
</crown>
7+
<meta key="author">AppSpace Sample</meta>
8+
<meta key="version">2.5.0</meta>
9+
<meta key="licensed">false</meta>
10+
<meta key="priority">low</meta>
11+
<meta key="copy-protected">false</meta>
12+
<meta key="read-protected">false</meta>
13+
<meta key="tags">Lua</meta>
14+
<entry path="scripts" default="StringStreaming.lua">
15+
<file type="text/x-lua">StringStreaming.lua</file>
16+
</entry>
17+
</application>
18+
</manifest>
+48-50
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,48 @@
1-
2-
--Start of Global Scope---------------------------------------------------------
3-
4-
-- Data which is streamed
5-
local SHORT = 1346
6-
local BYTE = 76
7-
local LONG = 2464321
8-
9-
--End of Global Scope-----------------------------------------------------------
10-
11-
--Start of Function and Event Scope-----------------------------------------------
12-
13-
--@packStringString()
14-
local function packString()
15-
--'HBL' = Unsinged short (H), unsinged byte (B) and unsinged long (L)
16-
--More information about the format can be found in the string component description
17-
local binaryString = string.pack('HBL', SHORT, BYTE, LONG)
18-
-- Writing data to file
19-
local file = File.open('/private/TestStringPacks.bin', 'wb')
20-
assert(file, 'File could not be opened to write')
21-
File.write(file, binaryString)
22-
File.close(file)
23-
end
24-
25-
--@unpackString()
26-
local function unpackString()
27-
-- Reading binary data from file
28-
local file = File.open('/private/TestStringPacks.bin', 'rb')
29-
assert(file, 'File could not be opened to read')
30-
local data = File.read(file)
31-
File.close(file)
32-
33-
-- Unpacking binary data read from file
34-
local value1, value2, value3 = string.unpack('HBL', data)
35-
print('value 1 read: ' .. tostring(value1))
36-
print('value 2 read: ' .. tostring(value2))
37-
print('value 3 read: ' .. tostring(value3))
38-
end
39-
40-
--Declaration of the 'main' function as an entry point for the event loop.
41-
--@main()
42-
local function main()
43-
packString()
44-
unpackString()
45-
end
46-
--The following registration is part of the global scope which runs once after startup
47-
--Registration of the 'main' function to the Engine.OnStarted event
48-
Script.register('Engine.OnStarted', main)
49-
50-
--End of Function and Event Scope-----------------------------------------------
1+
2+
--Start of Global Scope---------------------------------------------------------
3+
4+
-- Data which is streamed
5+
local SHORT = 1346
6+
local BYTE = 76
7+
local LONG = 2464321
8+
9+
--End of Global Scope-----------------------------------------------------------
10+
11+
--Start of Function and Event Scope-----------------------------------------------
12+
13+
local function packString()
14+
--'HBL' = Unsinged short (H), unsinged byte (B) and unsinged long (L)
15+
--More information about the format can be found in the string component description
16+
local binaryString = string.pack('HBL', SHORT, BYTE, LONG)
17+
-- Writing data to file
18+
local file = File.open('/private/TestStringPacks.bin', 'wb')
19+
assert(file, 'File could not be opened to write')
20+
File.write(file, binaryString)
21+
File.close(file)
22+
end
23+
24+
local function unpackString()
25+
-- Reading binary data from file
26+
local file = File.open('/private/TestStringPacks.bin', 'rb')
27+
assert(file, 'File could not be opened to read')
28+
local data = File.read(file)
29+
File.close(file)
30+
31+
-- Unpacking binary data read from file
32+
local value1, value2, value3 = string.unpack('HBL', data)
33+
print('value 1 read: ' .. tostring(value1))
34+
print('value 2 read: ' .. tostring(value2))
35+
print('value 3 read: ' .. tostring(value3))
36+
end
37+
38+
---Declaration of the 'main' function as an entry point for the event loop.
39+
local function main()
40+
packString()
41+
unpackString()
42+
end
43+
44+
--The following registration is part of the global scope which runs once after startup
45+
--Registration of the 'main' function to the Engine.OnStarted event
46+
Script.register('Engine.OnStarted', main)
47+
48+
--End of Function and Event Scope-----------------------------------------------

readme.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## StringStreaming
2+
23
Streaming binary data using the Lua functions string.pack() / string.unpack().
34

45
### Description
6+
57
This sample shows the streaming of data packed with the Lua string.pack function.
68
First the data is packed (serialized in binary form) and written to a file.
79
Then the same file is read, unpacked and the data is stored back to variables.
@@ -11,4 +13,5 @@ information about the format string can be found in the component description or
1113
in the Lua reference manual.
1214

1315
### Topics
14-
Programming-Pattern, Sample, SICK-AppSpace
16+
17+
programming-pattern, sample, sick-appspace

0 commit comments

Comments
 (0)