Skip to content

Commit e43f82d

Browse files
committed
Blobs;
1 parent 2b83ca5 commit e43f82d

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed

docs/Blob.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
category: reference
3+
-->
4+
5+
Blob
6+
===
7+
8+
A Blob is an object that represents the contents of a file. It can be passed to most functions that
9+
create objects from file data, such as `lovr.graphics.newModel` and `lovr.audio.newSource`. Loading
10+
many objects in this way is often faster because the file data only needs to be read once and can be
11+
reused. It can also be useful if file data is retrieved from some non-filesystem source, such as a
12+
network request.
13+
14+
Functions
15+
---
16+
17+
<table>
18+
<tr>
19+
<td class="pre">lovr.filesystem.newBlob</td>
20+
<td>Create a Blob from a file or raw data.</td>
21+
</tr>
22+
23+
<tr>
24+
<td class="pre">Blob:getFilename</td>
25+
<td>Return the name of the file used to load the Blob (or the user-defined name).</td>
26+
</tr>
27+
28+
<tr>
29+
<td class="pre">Blob:getPointer</td>
30+
<td>Return a raw pointer to the Blob's data.</td>
31+
</tr>
32+
33+
<tr>
34+
<td class="pre">Blob:getSize</td>
35+
<td>Return the size of the Blob's data, in bytes.</td>
36+
</tr>
37+
38+
<tr>
39+
<td class="pre">Blob:getString</td>
40+
<td>Return a string containing the binary blob data.</td>
41+
</tr>
42+
</table>

docs/Blob:getFilename.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--
2+
category: reference
3+
-->
4+
5+
Blob:getFilename
6+
===
7+
8+
Returns the name of the file used to load the Blob, or the custom name given to it when it was
9+
created.
10+
11+
filename = blob:getFilename()
12+
13+
### Arguments
14+
15+
None
16+
17+
### Returns
18+
19+
- `string filename` The name of the Blob.

docs/Blob:getPointer.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--
2+
category: reference
3+
-->
4+
5+
Blob:getPointer
6+
===
7+
8+
Returns a raw pointer to the Blob's data. This can be used to interface with other C libraries
9+
using the LuaJIT FFI. Use this only if you know what you're doing!
10+
11+
pointer = blob:getPointer()
12+
13+
### Arguments
14+
15+
None
16+
17+
### Returns
18+
19+
- `userdata pointer` A pointer to the data.

docs/Blob:getSize.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!--
2+
category: reference
3+
-->
4+
5+
Blob:getSize
6+
===
7+
8+
Get the size of a Blob's data in bytes.
9+
10+
bytes = blob:getSize()
11+
12+
### Arguments
13+
14+
None
15+
16+
### Returns
17+
18+
- `number bytes` The size of the data.

docs/Blob:getString.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
category: reference
3+
-->
4+
5+
Blob:getString
6+
===
7+
8+
Get the binary data of the Blob.
9+
10+
data = blob:getString()
11+
12+
### Arguments
13+
14+
None
15+
16+
### Returns
17+
18+
- `string data` The Blob data.
19+
20+
Example
21+
---
22+
23+
Manually copy a file using Blobs:
24+
25+
```
26+
blob = lovr.filesystem.newBlob('image.png')
27+
lovr.filesystem.write('copy.png', blob:getString())
28+
```

docs/lovr.filesystem.newBlob.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
category: reference
3+
-->
4+
5+
lovr.filesystem.newBlob
6+
===
7+
8+
Creates a new Blob. A Blob is an object that represents the contents of a file. It can be passed
9+
to most functions that create objects from file data, such as `lovr.graphics.newModel` and
10+
`lovr.audio.newSource`. Loading many objects in this way is often faster because the file data
11+
only needs to be read once and can be reused. It can also be useful if file data is retrieved from
12+
some non-filesystem source, such as a network request.
13+
14+
---
15+
16+
blob = lovr.filesystem.newBlob(filename)
17+
18+
### Arguments
19+
20+
- `string filename` The file to load.
21+
22+
### Returns
23+
24+
- `Blob blob` The new Blob.
25+
26+
---
27+
28+
blob = lovr.filesystem.newBlob(str, name)
29+
30+
### Arguments
31+
32+
- `string str` The contents of the Blob.
33+
- `string name` A name for the Blob (used for error messages).
34+
35+
### Returns
36+
37+
- `Blob blob` A new Blob.
38+
39+
See also
40+
---
41+
42+
- `Blob`

0 commit comments

Comments
 (0)