Difference between revisions of "Lua:encodeFunction"
Jump to navigation
Jump to search
(Tag: Undo) |
(Major overhaul of the post.) |
||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | '''function''' encodeFunction(''function'' | + | {{CodeBox|'''function''' encodeFunction(''function'') ''':''' string}} |
| − | Converts a given function into an encoded string | + | 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 | + | {|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 |
| − | |The function | + | |The Lua function that should be encoded. |
|} | |} | ||
| − | == Examples == | + | ===Returns=== |
| + | String — The encoded function string. | ||
| + | |||
| + | ===Examples=== | ||
| + | <pre> | ||
| + | local encoded = encodeFunction(function() | ||
| + | print("Hello from an encoded function") | ||
| + | end) | ||
| + | |||
| + | print(encoded) | ||
| + | </pre> | ||
| + | |||
<pre> | <pre> | ||
| − | local function | + | local encoded = encodeFunction(function(value) |
| − | print( | + | return value * 2 |
| + | end) | ||
| + | |||
| + | local decoded = decodeFunction(encoded) | ||
| + | |||
| + | print(decoded(21)) | ||
</pre> | </pre> | ||
| + | |||
<pre> | <pre> | ||
| − | local function | + | local function testFunction() |
| − | local | + | showMessage("This function was encoded and decoded") |
| − | local | + | end |
| − | + | ||
| + | local encoded = encodeFunction(testFunction) | ||
| + | local decoded = decodeFunction(encoded) | ||
| + | |||
| + | decoded() | ||
</pre> | </pre> | ||
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
| − | = | + | {{LuaIndexBoxNoDescription |
| − | + | |title=Function Encoding Related Lua Functions | |
| + | |content= | ||
| + | {{LuaIndexItemNoDescription | ||
| + | |page=encodeFunction | ||
| + | |label=encodeFunction | ||
| + | }} | ||
| + | {{LuaIndexItemNoDescription | ||
| + | |page=decodeFunction | ||
| + | |label=decodeFunction | ||
| + | }} | ||
| + | {{LuaIndexItemNoDescription | ||
| + | |page=encodeFunctionEx | ||
| + | |label=encodeFunctionEx | ||
| + | }} | ||
| + | }} | ||
Revision as of 14:14, 25 June 2026
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
local encoded = encodeFunction(function()
print("Hello from an encoded function")
end)
print(encoded)
local encoded = encodeFunction(function(value) return value * 2 end) local decoded = decodeFunction(encoded) print(decoded(21))
local function testFunction()
showMessage("This function was encoded and decoded")
end
local encoded = encodeFunction(testFunction)
local decoded = decodeFunction(encoded)
decoded()