Difference between revisions of "Lua:Class:StringStream"

From Cheat Engine
Jump to navigation Jump to search
(Major overhaul of the post.)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
StringStream '''class''': ('''Inheritance''': ''[[Lua:Class:Stream|Stream]]''->''[[Lua:Class:Object|Object]]'')
+
{{CodeBox|'''class''' StringStream ''':''' Stream}}
  
Class for using [[Lua:Class:Stream|Stream]] objects as a [[Lua:Class:Strings|Strings]] based object.
+
The StringStream class represents a stream backed by an internal string.
  
== Creation ==
+
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.
; [[Lua:createStringStream|createStringStream]]() : StringStream
 
: Returns a newly created string steam.
 
  
== Properties ==
+
===Inheritance===
; DataString : string
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: The internal string
+
!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.
 +
|}
  
== Examples ==
+
===Creation===
local fileStr = nil
+
{{CodeBox|'''function''' createStringStream(''string'') ''':''' StringStream}}
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
 
  
== See also ==
+
Creates a StringStream object initialized with the given string.
* [[Lua]]
 
* [[Help_File:Script engine|Script engine]]
 
  
=== Related Functions ===
+
===Function Parameters===
* [[Lua:createStringStream|createStringStream]]
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
* [[Lua:createMemoryStream|createMemoryStream]]
+
!align="left"|Parameter
* [[Lua:createFileStream|createFileStream]]
+
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|string
 +
|String
 +
|The initial string data for the StringStream.
 +
|}
  
=== Related Classes ===
+
===Returns===
* [[Lua:Class:MemoryStream|MemoryStream]]
+
StringStream — The created StringStream object.
* [[Lua:Class:FileStream|FileStream]]
+
 
* [[Lua:Class:Stream|Stream]]
+
===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===
 +
<pre>
 +
local stream = createStringStream("Hello World")
 +
 
 +
print(stream.DataString)
 +
 
 +
stream.destroy()
 +
</pre>
 +
 
 +
<pre>
 +
local stream = createStringStream("Initial text")
 +
 
 +
stream.DataString = "Changed text"
 +
 
 +
print(stream.DataString)
 +
 
 +
stream.destroy()
 +
</pre>
 +
 
 +
<pre>
 +
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
 +
</pre>
 +
 
 +
{{LuaSeeAlso}}

Revision as of 17:12, 21 June 2026

<> Lua API Reference

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

Class Inherits From Description
StringStream Stream A stream object backed by an internal string.
Stream Object Base class for stream objects.

Creation

<> Lua API Reference

function createStringStream(string) : StringStream

Creates a StringStream object initialized with the given string.

Function Parameters

Parameter Type Description
string String The initial string data for the StringStream.

Returns

StringStream — The created StringStream object.

Properties

Property Type Description
DataString String The internal string stored by the StringStream.

Methods

This class has no documented methods beyond the inherited stream methods.

Examples

local stream = createStringStream("Hello World")

print(stream.DataString)

stream.destroy()
local stream = createStringStream("Initial text")

stream.DataString = "Changed text"

print(stream.DataString)

stream.destroy()
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

Main Pages

Core Lua documentation entry points

Lua
Script Engine