Difference between revisions of "Lua:Class:StringStream"
Jump to navigation
Jump to search
m (Syntax Highlighting.) |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | + | {{Class|'''class''' StringStream ''':''' Stream}} | |
| − | + | The StringStream class represents a stream backed by an internal string. | |
| − | + | A StringStream inherits from Stream and Object. It can be created with createStringStream and is useful when stream operations should be performed on string data. | |
| − | |||
| − | |||
| − | == | + | ===Inheritance=== |
| − | ; | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
| − | + | !align="left"|Class | |
| + | !align="left"|Inherits From | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |StringStream | ||
| + | |Stream | ||
| + | |A stream object backed by an internal string. | ||
| + | |- | ||
| + | |Stream | ||
| + | |Object | ||
| + | |Base class for stream objects. | ||
| + | |} | ||
| − | == | + | ===Creation=== |
| − | + | {{CodeBox|'''function''' createStringStream(''string'') ''':''' StringStream}} | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Creates a StringStream object initialized with the given string. | |
| − | |||
| − | |||
| − | === | + | ===Function Parameters=== |
| − | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | |
| − | + | !align="left"|Parameter | |
| − | + | !align="left"|Type | |
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |string | ||
| + | |String | ||
| + | |The initial string data for the StringStream. | ||
| + | |} | ||
| − | === | + | ===Returns=== |
| − | + | StringStream — The created StringStream object. | |
| − | + | ||
| − | + | ===Properties=== | |
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Property | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |DataString | ||
| + | |String | ||
| + | |The internal string stored by the StringStream. | ||
| + | |} | ||
| + | |||
| + | ===Methods=== | ||
| + | This class has no documented methods beyond the inherited stream methods. | ||
| + | |||
| + | ===Examples=== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local stream = createStringStream("Hello World") | ||
| + | |||
| + | print(stream.DataString) | ||
| + | |||
| + | stream.destroy() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local stream = createStringStream("Initial text") | ||
| + | |||
| + | stream.DataString = "Changed text" | ||
| + | |||
| + | print(stream.DataString) | ||
| + | |||
| + | stream.destroy() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local fileStr = nil | ||
| + | local tableFile = findTableFile('PlayerBaseHook.CEA') | ||
| + | if tableFile ~= nil then | ||
| + | local stringStream = createStringStream() | ||
| + | stringStream.Position = 0 -- if not set before using 'copyFrom' the 'StringStream' object will be inconsistent. | ||
| + | stringStream.copyFrom(tableFile.Stream, tableFile.Stream.Size) | ||
| + | fileStr = stringStream.DataString | ||
| + | stringStream.destroy() | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | {{LuaSeeAlso}} | ||
Latest revision as of 23:18, 26 June 2026
The StringStream class represents a stream backed by an internal string.
A StringStream inherits from Stream and Object. It can be created with createStringStream and is useful when stream operations should be performed on string data.
Inheritance[edit]
| Class | Inherits From | Description |
|---|---|---|
| StringStream | Stream | A stream object backed by an internal string. |
| Stream | Object | Base class for stream objects. |
Creation[edit]
Creates a StringStream object initialized with the given string.
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| string | String | The initial string data for the StringStream. |
Returns[edit]
StringStream — The created StringStream object.
Properties[edit]
| Property | Type | Description |
|---|---|---|
| DataString | String | The internal string stored by the StringStream. |
Methods[edit]
This class has no documented methods beyond the inherited stream methods.
Examples[edit]
1 local stream = createStringStream("Hello World")
2
3 print(stream.DataString)
4
5 stream.destroy()
1 local stream = createStringStream("Initial text")
2
3 stream.DataString = "Changed text"
4
5 print(stream.DataString)
6
7 stream.destroy()
1 local fileStr = nil
2 local tableFile = findTableFile('PlayerBaseHook.CEA')
3 if tableFile ~= nil then
4 local stringStream = createStringStream()
5 stringStream.Position = 0 -- if not set before using 'copyFrom' the 'StringStream' object will be inconsistent.
6 stringStream.copyFrom(tableFile.Stream, tableFile.Stream.Size)
7 fileStr = stringStream.DataString
8 stringStream.destroy()
9 end