Skip to content

Commit be0a4e3

Browse files
authored
Merge pull request #38 from Joe7M/master
Website cleanup and bugfixing
2 parents 670d6c4 + 842a47b commit be0a4e3

File tree

229 files changed

+2729
-1291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+2729
-1291
lines changed

_build/mkdata.bas

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ rem
22
rem reads reference.json to produce per page json data files
33
rem
44

5-
const samplesPath = "/home/chrisws/src/smallbasic.samples/"
5+
const samplesPath = "/home/j7m/Programmieren/Basic/GIT/DickesDing/smallbasic.samples/"
66

77
tload "reference.json", s, 1
88
ref = array(s)

_build/pages/index.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
> algebra functions, a built in IDE, a powerful string library, system, sound, graphic
66
> commands and communication via serial or sockets along with structured programming syntax.
77
8-
![](../images/sb_logo_text.png){ style="display: block; margin-left: auto; margin-right: auto; padding-bottom:2em;"}
8+
![](../images/sb-logo_text.png){ style="display: block; margin-left: auto; margin-right: auto; padding-top:2em; padding-bottom:2em;"}
99

1010
[Download](pages/download.html){.LinkIndexPage} [Try online](https://smallbasic.github.io/online/sbasic.html){.LinkIndexPage}
1111

_build/reference/598-file-tload.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Loads a text file `file` into the array variable `var`. Each text-line is an arr
77
- `0`: load into array (default)
88
- `1`: load into string
99

10+
See TSAVE for writing variables to a file.
11+
1012
### Example 1
1113

1214
```

_build/reference/599-file-tsave.markdown

+40-10
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
> TSAVE file, var
44
5-
Writes the array or string `var` to the text file `file`. Each array element is a text-line in the file. Every line of the string will be one line in the text file. Use `\n` in the string to separate lines.
5+
Writes array, map or string `var` to the text file `file`. Each array element is a text-line in the file. Every line of the string will be one line in the text file. Use `\n` in the string to separate lines. Maps will be saved as a json string.
66

77
See TLOAD for loading data from a text-file.
88

9-
### Example 1: Save an array
9+
### Example 1
1010

1111
```
1212
' Create an array with some data
@@ -24,20 +24,50 @@ tload "myfile.txt", B
2424
print B ' Output: [1,test,2,]
2525
```
2626

27-
### Example 2: Save a string
27+
### Example 2: Writing maps as json data
2828

2929
```
30-
' Create a string with some data
31-
A = "line 1\nline 2\nline 3"
32-
print A ' Output: line 1
33-
' line 2
34-
' line 3
30+
' Create an array with some json data
31+
A << {name: "Ben", age: 20}
32+
A << {name: "Alice", age: 22}
3533
36-
' Save the string. This will create the file myfile.txt in
34+
' Save the array. This will create the file myfile.txt in
3735
' the same directory as your BASIC file
3836
tsave "myfile.txt", A
3937
4038
' Load the file
4139
tload "myfile.txt", B
42-
print B ' Output: [line 1,line 2,line 3]
40+
41+
' Convert B to map variable
42+
for element in B
43+
M << array(element)
44+
next
45+
46+
print M
47+
print M[1].age
48+
49+
' Output:
50+
' [{"age":20,"name":"Ben"},{"age":22,"name":"Alice"},0]
51+
' 22
52+
```
53+
54+
### Example 3: Write a string
55+
56+
```
57+
' Create an array with some data
58+
A << 1
59+
A << "test"
60+
A << 2
61+
print A ' Output: [1,test,2]
62+
63+
' Save the array. This will create the file myfile.txt in
64+
' the same directory as your BASIC file
65+
tsave "myfile.txt", A
66+
67+
' Load the file
68+
tload "myfile.txt", B, 1
69+
print "->"; B ; "<-" ' Output: ->1
70+
' test
71+
' 2
72+
' <-
4373
```

0 commit comments

Comments
 (0)