Difference between revisions of "Lua:encodeFunction"

From Cheat Engine
Jump to navigation Jump to search
(Major overhaul of the post.)
m (Syntax Highlighting.)
Line 21: Line 21:
  
 
===Examples===
 
===Examples===
<pre>
+
<syntaxhighlight lang="lua" line>
 
local encoded = encodeFunction(function()
 
local encoded = encodeFunction(function()
 
   print("Hello from an encoded function")
 
   print("Hello from an encoded function")
Line 27: Line 27:
  
 
print(encoded)
 
print(encoded)
</pre>
+
</syntaxhighlight>
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local encoded = encodeFunction(function(value)
 
local encoded = encodeFunction(function(value)
 
   return value * 2
 
   return value * 2
Line 37: Line 37:
  
 
print(decoded(21))
 
print(decoded(21))
</pre>
+
</syntaxhighlight>
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local function testFunction()
 
local function testFunction()
 
   showMessage("This function was encoded and decoded")
 
   showMessage("This function was encoded and decoded")
Line 48: Line 48:
  
 
decoded()
 
decoded()
</pre>
+
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}

Revision as of 16:26, 25 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

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

Returns

String — The encoded function string.

Examples

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