Skip to content
Skills Library
Programming · Building & coding

zlua-delegate

/zlua-delegate

Marshals Lua functions and C# delegates: implicit Action and Func parameters, calling a callback from Lua, zlua.to_delegate, and add_/remove_ events. Use when a C# API takes or returns a delegate, Action, Func, or event handler.

Repository
unity-mcp ↗
Licence
MIT
Last repository change
02.11.2026

Assessment and security

95/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content30 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 02.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Marshals Lua functions and C# delegates: implicit Action and Func parameters, calling a callback from Lua, zlua.to_delegate, and add_/remove_ events. Use when a C# API takes or returns a delegate, Action, Func, or event handler.

Original author description

Marshals Lua functions and C# delegates: implicit Action and Func parameters, calling a callback from Lua, zlua.to_delegate, and add_/remove_ events. Use when a C# API takes or returns a delegate, Action, Func, or event handler.

How it works

  1. Lua function as a parameter
  2. Callbacks returned to Lua
Original SKILL.md headings · 55 lines, 269 words
SKILL.md preview
---
name: zlua-delegate
description: >-
  Marshals Lua functions and C# delegates: implicit Action and Func parameters,
  calling a callback from Lua, zlua.to_delegate, and add_/remove_ events.
  Use when a C# API takes or returns a delegate, Action, Func, or event handler.
---

# Delegates

Three paths. Do not collapse them into one.

| Path | How |
|------|-----|
| Lua function passed into a C# parameter | Pass `function(...) end`. ZLua builds a closed delegate from the parameter type |
| C# callback handed to Lua | Call it: `handler(...)`. It may be a Lua function or delegate userdata |
| C# calls a named Lua export | `LuaAppDomain.GetFunction<T>(module, method)`. See `zlua-csharp-call-lua` |

## Lua function as a parameter

```csharp
public void RegisterCallback(System.Action<int> onValue)
{
    onValue?.Invoke(42);
}
```

```lua
host:RegisterCallback(function(v)
    print("callback:", v)
end)

logic.Combine = function(a, b) return a + b end
```

| Lua argument | Result |
|--------------|--------|
| `function` | New closed delegate of the parameter type |
| `nil` | `null` |
| Existing delegate userdata | Passed through |
| Anything else | Type error |

Do not call `zlua.to_delegate` for this case. Use `zlua.to_delegate(fn, closedDelegateType)` only when Lua already has a function and the delegate type is not fixed by a C# parameter. The type argument must be a closed type such as `Action<int>`, not an open generic.

## Callbacks returned to Lua

```lua
local handler = host:GetHandler()
handler(42)
```

| Origin | `type(handler)` | Call |
|--------|-----------------|------|
| C# delegate | userdata with `__call` | `handler(...)` |
| Lua function that round-tripped through C# | `function` | `handler(...)` |

Do not use `handler:Invoke(...)`. That fails on a raw Lua function. An open delegate (`target == null`) is not supported.

`params` on a delegate bridge or on `GetFunction` is not supported. See `zlua-params`.

Events use `add_` / `remove_` with the same function reference. See `zlua-lua-call-csharp`.

Versions

The database has no other skills named zlua-delegate.

Database snapshot: 13.11.2026 · package version 6d84c4b9e1dd (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 95zlua-in-ref-out
    Marshals C# ref, in, and out parameters with ZLua. Use when a method has ref, in, or out arguments, when Lua should receive multiple results from out parameters, or when a byref write does not show up in the Lua value.
  • 95zlua-csharp-call-lua
    Calls Lua from C# with LuaAppDomain.Initialize and GetFunction. Use when writing a module loader, binding Action or Func to a Lua module method, or reloading scripts with Reset.
  • 85Lua C Integration
    Use when lua C API for extending Lua with native code including stack operations, calling C from Lua, calling Lua from C, creating C modules, userdata types, metatables in C, and performance optimization techniques.
  • 90lua-guide
    Use when editing general-purpose Lua 5.4+: modules, scripts, configuration. Triggers on `.lua` files and prompts about module patterns, local scoping, metatables, coroutines, error handling, even when the user doesn't say 'Lua'.
  • 90rayfin-functions
    Use when writing Rayfin user-defined functions (UDFs), invoking functions from frontend code, or using functions CLI commands. Triggers: rayfin functions, udf.func, UserDataFunctions, RayfinContext, FabricContext, AppFunctionsSchema, functions init, dev functions apply,…
  • 100grandma3-lua-api
    Write, debug, and reason about grandMA3 Lua plugins and scripting — the Object API and Object-Free API (Cmd, Printf, Get/Set, handles, UI dialogs, progress bars), plugin XML/structure, and showfile paths. Use when a user asks to write a grandMA3 plugin or Lua script, automate a…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.