Difference between revisions of "Lua:encodeFunction"

From Cheat Engine
Jump to navigation Jump to search
(Created page with 'Category:Lua '''function''' encodeFunction(''function'', ''protect'' OPTIONAL) ''':''' string Converts a given function into an encoded string that you can pass to [[Lua:fin…')
 
m (Added related function template.)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' encodeFunction(''function'', ''protect'' OPTIONAL) ''':''' string
+
{{CodeBox|'''function''' encodeFunction(''function'') ''':''' string}}
  
Converts a given function into an encoded string that you can pass to [[Lua:findTableFile|decodeFunction]].
+
Converts a given Lua function into an encoded string.
 +
 
 +
The encoded string can later be passed to [[Lua:decodeFunction|decodeFunction]] to recreate the function.
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
Line 11: Line 13:
 
|-
 
|-
 
|function
 
|function
|function
+
|Function
|The function to encode
+
|The Lua function that should be encoded.
 
|}
 
|}
  
== Examples ==
+
===Returns===
<pre>
+
String — The encoded function string.
local function myCoolFunction(str) print(str) end
+
 
print(encodeFunction(myCoolFunction))
+
===Examples===
</pre>
+
<syntaxhighlight lang="lua" line>
<pre>
+
local encoded = encodeFunction(function()
local function myCoolFunction(str) print(str) end
+
  print("Hello from an encoded function")
local encodedFunc = encodeFunction(myCoolFunction)
+
end)
local decodedFunc = decodeFunction(encodedFunc)
+
 
decodedFunc('I have the power!')
+
print(encoded)
</pre>
+
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua" line>
 +
local encoded = encodeFunction(function(value)
 +
  return value * 2
 +
end)
 +
 
 +
local decoded = decodeFunction(encoded)
 +
 
 +
print(decoded(21))
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua" line>
 +
local function testFunction()
 +
  showMessage("This function was encoded and decoded")
 +
end
 +
 
 +
local encoded = encodeFunction(testFunction)
 +
local decoded = decodeFunction(encoded)
 +
 
 +
decoded()
 +
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
=== Related Functions ===
+
{{EncodeDecode}}
* [[Lua:findTableFile|decodeFunction]]
 

Latest revision as of 00:11, 27 June 2026

<> Lua API Reference

function encodeFunction(function) : string

Converts a given Lua function into an encoded string.

The encoded string can later be passed to decodeFunction to recreate the function.

Function Parameters[edit]

Parameter Type Description
function Function The Lua function that should be encoded.

Returns[edit]

String — The encoded function string.

Examples[edit]

1 local encoded = encodeFunction(function()
2   print("Hello from an encoded function")
3 end)
4 
5 print(encoded)
1 local encoded = encodeFunction(function(value)
2   return value * 2
3 end)
4 
5 local decoded = decodeFunction(encoded)
6 
7 print(decoded(21))
1 local function testFunction()
2   showMessage("This function was encoded and decoded")
3 end
4 
5 local encoded = encodeFunction(testFunction)
6 local decoded = decodeFunction(encoded)
7 
8 decoded()

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Function Encoding Related Lua Functions