Difference between revisions of "Lua:Class:Stringlist"

From Cheat Engine
Jump to navigation Jump to search
m
(Major overhaul of the post.)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
StringList '''class''': ('''Inheritance''': ''[[Lua:Class:Strings|Strings]]''->''[[Lua:Class:Object|Object]]'')
+
{{Class|'''class''' Stringlist ''':''' Strings}}
  
The Stringlist class represents a list of strings with optional sorting, duplicate handling, and case sensitivity. 
+
The Stringlist class represents a mutable list of strings.
You can create a Stringlist object using <code>createStringlist()</code>.
 
  
== Properties ==
+
It inherits from [[Lua:Class:Strings|Strings]] and adds sorting, duplicate handling, and case-sensitivity behavior.
{| class="wikitable" style="width:100%"
+
 
! Property
+
===Inheritance===
! Type
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
! Description
+
!align="left"|Class
|-
+
!align="left"|Inherits From
| Sorted
+
!style="width: 80%;background-color:white;" align="left"|Description
| Boolean
 
| Determines if the list should be sorted.
 
 
|-
 
|-
| Duplicates
+
|Stringlist
| [[DuplicatesType]]
+
|Strings
| Determines how duplicates are handled when the list is sorted (see enum below).
+
|A string list object with sorting and duplicate handling options.
 
|-
 
|-
| CaseSensitive
+
|Strings
| Boolean
+
|Object
| Determines if the list is case sensitive.
+
|Base class for string collection objects.
 
|}
 
|}
  
== Methods ==
+
===Creation===
{| class="wikitable" style="width:100%"
+
{{CodeBox|'''function''' createStringlist() ''':''' Stringlist}}
! Method
+
 
! Parameters
+
Creates a Stringlist class object.
! Returns
+
 
! Description
+
===Function Parameters===
 +
This function has no parameters.
 +
 
 +
===Returns===
 +
Stringlist — The created Stringlist 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
 
|-
 
|-
| getDuplicates
+
|Sorted
| None
+
|Boolean
| [[DuplicatesType]]
+
|Determines if the list should be sorted.
| Returns the duplicates property.
 
 
|-
 
|-
| setDuplicates
+
|Duplicates
| [[DuplicatesType]]
+
|[[DuplicatesType]]
| None
+
|Determines how duplicates should be handled when the list is sorted.
| Sets the duplicates property (<code>dupIgnore</code>, <code>dupAccept</code>, <code>dupError</code>).
 
 
|-
 
|-
| getSorted
+
|CaseSensitive
| None
+
|Boolean
| Boolean
+
|Determines if the list is case sensitive.
| Returns true if the list is sorted.
+
|}
 +
 
 +
===DuplicatesType===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Constant
 +
!align="left"|Value
 +
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
| setSorted
+
|dupIgnore
| Boolean
+
|0
| None
+
|Ignores duplicate values.
| Sets the sorted property.
 
 
|-
 
|-
| getCaseSensitive
+
|dupAccept
| None
+
|1
| Boolean
+
|Accepts duplicate values.
| Returns true if the list is case sensitive.
 
 
|-
 
|-
| setCaseSensitive
+
|dupError
| Boolean
+
|2
| None
+
|Raises an error when a duplicate value is added.
| Sets the case sensitive property.
 
 
|}
 
|}
  
== DuplicatesType Enum ==
+
===Methods===
{| class="wikitable"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
! Name
+
!align="left"|Method
! Value
+
!align="left"|Return Type
! Description
+
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|getDuplicates()
 +
|[[DuplicatesType]]
 +
|Returns the Duplicates property.
 +
|-
 +
|setDuplicates(Duplicates)
 +
|void
 +
|Sets the Duplicates property. Valid values are dupIgnore, dupAccept, and dupError.
 
|-
 
|-
| dupIgnore
+
|getSorted()
| 0
+
|Boolean
| Ignore duplicate entries.
+
|Returns true if the Sorted property is enabled.
 
|-
 
|-
| dupAccept
+
|setSorted(boolean)
| 1
+
|void
| Accept duplicate entries.
+
|Sets the Sorted property.
 
|-
 
|-
| dupError
+
|getCaseSensitive()
| 2
+
|Boolean
| Raise an error on duplicate entries.
+
|Returns true if the CaseSensitive property is enabled.
 +
|-
 +
|setCaseSensitive(boolean)
 +
|void
 +
|Sets the CaseSensitive property.
 
|}
 
|}
 +
 +
===Examples===
 +
<pre>
 +
local list = createStringlist()
 +
 +
list.add("Banana")
 +
list.add("Apple")
 +
list.add("Cherry")
 +
 +
list.Sorted = true
 +
 +
for i = 0, list.Count - 1 do
 +
  print(list[i])
 +
end
 +
 +
list.destroy()
 +
</pre>
 +
 +
<pre>
 +
local list = createStringlist()
 +
 +
list.Sorted = true
 +
list.Duplicates = dupIgnore
 +
 +
list.add("Apple")
 +
list.add("Apple")
 +
list.add("Banana")
 +
 +
for i = 0, list.Count - 1 do
 +
  print(list[i])
 +
end
 +
 +
list.destroy()
 +
</pre>
 +
 +
<pre>
 +
local list = createStringlist()
 +
 +
list.CaseSensitive = false
 +
list.Sorted = true
 +
list.Duplicates = dupError
 +
 +
list.add("Apple")
 +
 +
local success, err = pcall(function()
 +
  list.add("apple")
 +
end)
 +
 +
if not success then
 +
  print("Duplicate error: " .. tostring(err))
 +
end
 +
 +
list.destroy()
 +
</pre>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
 
=== Related Classes ===
 
* [[Lua:Class:Object|Object]]
 
* [[Lua:Class:Strings|Strings]]
 

Revision as of 14:24, 25 June 2026

{} Class

class Stringlist : Strings

The Stringlist class represents a mutable list of strings.

It inherits from Strings and adds sorting, duplicate handling, and case-sensitivity behavior.

Inheritance

Class Inherits From Description
Stringlist Strings A string list object with sorting and duplicate handling options.
Strings Object Base class for string collection objects.

Creation

<> Lua API Reference

function createStringlist() : Stringlist

Creates a Stringlist class object.

Function Parameters

This function has no parameters.

Returns

Stringlist — The created Stringlist object.

Properties

Property Type Description
Sorted Boolean Determines if the list should be sorted.
Duplicates DuplicatesType Determines how duplicates should be handled when the list is sorted.
CaseSensitive Boolean Determines if the list is case sensitive.

DuplicatesType

Constant Value Description
dupIgnore 0 Ignores duplicate values.
dupAccept 1 Accepts duplicate values.
dupError 2 Raises an error when a duplicate value is added.

Methods

Method Return Type Description
getDuplicates() DuplicatesType Returns the Duplicates property.
setDuplicates(Duplicates) void Sets the Duplicates property. Valid values are dupIgnore, dupAccept, and dupError.
getSorted() Boolean Returns true if the Sorted property is enabled.
setSorted(boolean) void Sets the Sorted property.
getCaseSensitive() Boolean Returns true if the CaseSensitive property is enabled.
setCaseSensitive(boolean) void Sets the CaseSensitive property.

Examples

local list = createStringlist()

list.add("Banana")
list.add("Apple")
list.add("Cherry")

list.Sorted = true

for i = 0, list.Count - 1 do
  print(list[i])
end

list.destroy()
local list = createStringlist()

list.Sorted = true
list.Duplicates = dupIgnore

list.add("Apple")
list.add("Apple")
list.add("Banana")

for i = 0, list.Count - 1 do
  print(list[i])
end

list.destroy()
local list = createStringlist()

list.CaseSensitive = false
list.Sorted = true
list.Duplicates = dupError

list.add("Apple")

local success, err = pcall(function()
  list.add("apple")
end)

if not success then
  print("Duplicate error: " .. tostring(err))
end

list.destroy()

Main Pages

Core Lua documentation entry points

Lua
Script Engine