Difference between revisions of "Lua:Class:Stringlist"

From Cheat Engine
Jump to navigation Jump to search
(filled out a proper class template for the StringList class)
m (Syntax Highlighting.)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
StringList '''class''': ('''Inheritance''': ''[[Lua:Class:Strings|Strings]]''->''[[Lua:Class:Object|Object]]'')
+
{{Class|'''class''' Stringlist ''':''' Strings}}
  
Basically, a wrapper around the [[Lua:Class:Strings|Strings]] class.
+
The Stringlist class represents a mutable list of strings.
  
== Related Globals ==
+
It inherits from [[Lua:Class:Strings|Strings]] and adds sorting, duplicate handling, and case-sensitivity behavior.
; createStringList() : StringList
 
: Creates a stringList object.
 
  
; DuplicatesType : number
+
===Inheritance===
: These are declared globally and their ''type()'' is of ''number''.
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: They act like an enum object for the Duplicates property.
+
!align="left"|Class
: 0 : dupIgnore
+
!align="left"|Inherits From
: 1 : dupAccept
+
!style="width: 80%;background-color:white;" align="left"|Description
: 2 : dupError
+
|-
 +
|Stringlist
 +
|Strings
 +
|A string list object with sorting and duplicate handling options.
 +
|-
 +
|Strings
 +
|Object
 +
|Base class for string collection objects.
 +
|}
  
== Properties ==
+
===Creation===
; Duplicates : DuplicatesType
+
{{CodeBox|'''function''' createStringlist() ''':''' Stringlist}}
: Determines how duplicates should be handled.
 
: ''Note: Does not seem to work.''
 
  
; Sorted : boolean
+
Creates a Stringlist class object.
: Determines if the list should be sorted.
 
  
; CaseSensitive : boolean
+
===Function Parameters===
: Determines if case sensitivity is considered when sorting the list.
+
This function has no parameters.
: ''Note: This has no effect on the actual cases of the actual strings.
 
  
== Methods ==
+
===Returns===
; getDuplicates() : DuplicatesType
+
Stringlist — The created Stringlist object.
: Returns the Duplicates property.
 
  
; setDuplicates(DuplicatesType)
+
===Properties===
: Sets the Duplicates property (dupIgnore, dupAccept, dupError).
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: ''Note: Again, this does not seem to have any actual effect.''
+
!align="left"|Property
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|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.
 +
|}
  
; getSorted() : boolean
+
===DuplicatesType===
: Returns the Sorted property.
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Constant
 +
!align="left"|Value
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|dupIgnore
 +
|0
 +
|Ignores duplicate values.
 +
|-
 +
|dupAccept
 +
|1
 +
|Accepts duplicate values.
 +
|-
 +
|dupError
 +
|2
 +
|Raises an error when a duplicate value is added.
 +
|}
  
; setSorted(boolean)
+
===Methods===
: Sets the Sorted property.
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Method
 +
!align="left"|Return Type
 +
!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.
 +
|-
 +
|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.
 +
|}
  
; getCaseSensitive() : boolean
+
===Examples===
: Returns the CaseSensitive property.
+
<syntaxhighlight lang="lua" line>
 +
local list = createStringlist()
  
; setCaseSensitive(boolean)
+
list.add("Banana")
: Sets the CaseSensitive property.
+
list.add("Apple")
 +
list.add("Cherry")
 +
 
 +
list.Sorted = true
 +
 
 +
for i = 0, list.Count - 1 do
 +
  print(list[i])
 +
end
 +
 
 +
list.destroy()
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua" line>
 +
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()
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua" line>
 +
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()
 +
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
 
=== Related Classes ===
 
* [[Lua:Class:Object|Object]]
 
* [[Lua:Class:Strings|Strings]]
 

Latest revision as of 19:45, 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[edit]

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[edit]

<> Lua API Reference

function createStringlist() : Stringlist

Creates a Stringlist class object.

Function Parameters[edit]

This function has no parameters.

Returns[edit]

Stringlist — The created Stringlist object.

Properties[edit]

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[edit]

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[edit]

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[edit]

 1 local list = createStringlist()
 2 
 3 list.add("Banana")
 4 list.add("Apple")
 5 list.add("Cherry")
 6 
 7 list.Sorted = true
 8 
 9 for i = 0, list.Count - 1 do
10   print(list[i])
11 end
12 
13 list.destroy()
 1 local list = createStringlist()
 2 
 3 list.Sorted = true
 4 list.Duplicates = dupIgnore
 5 
 6 list.add("Apple")
 7 list.add("Apple")
 8 list.add("Banana")
 9 
10 for i = 0, list.Count - 1 do
11   print(list[i])
12 end
13 
14 list.destroy()
 1 local list = createStringlist()
 2 
 3 list.CaseSensitive = false
 4 list.Sorted = true
 5 list.Duplicates = dupError
 6 
 7 list.add("Apple")
 8 
 9 local success, err = pcall(function()
10   list.add("apple")
11 end)
12 
13 if not success then
14   print("Duplicate error: " .. tostring(err))
15 end
16 
17 list.destroy()

Main Pages

Core Lua documentation entry points

Lua
Script Engine