This page describes the Lua shape produced by sf-transpile and the small runtime helpers it may emit.
Every transpiled namespace and type lives under one configurable root table. The default is SF__.
SF__ = SF__ or {}
SF__.Game = SF__.Game or {}
SF__.Game.Hero = SF__.Game.Hero or {}Override the root table with:
sf-transpile .\CSProject -o .\out.lua --root-table MyMod_SharpForge writes generated C# types under this one root table so it does not collide with hand-written Lua modules or war3map.lua globals.
Common C# constructs lower to direct Lua patterns:
| C# concept | Lua shape |
|---|---|
| Namespace | nested root-table fields |
| Static method | function SF__.Type.Method(...) |
| Instance method | function SF__.Type:Method(...) |
| Constructor | SF__.Type.New(...) with setmetatable |
this(...) constructor initializer |
current type __Init... call on self before the constructor body |
| Object creation | SF__.Type.New(...) |
| Object initializer assignment | temporary object plus assignments, then returned temporary |
float literal |
emitted as its source-faithful decimal (0.65f → 0.65, not 0.6499...) |
double literal |
emitted with full round-trip precision |
string.Empty |
empty string literal ("") |
| Struct field-only local | flattened locals named <local>__<field> |
| Struct object return | Lua multi-return in field declaration order |
| Instance field access | self.Field |
| Static field initializer | SF__.Type.Field = ... |
const field |
static type-table field (SF__.Type.Field = ...) |
| String interpolation | nil-safe SF__.StrConcat__(...) calls; supported format clauses use string.format(...) |
try / catch / finally |
Lua pcall scaffolding |
is / as |
emitted type metadata helpers when needed |
??= |
nil-check assignment; expression form returns the existing or assigned value |
List<T>, Dictionary<K,V> |
compact table helper runtimes |
C# line comments, block comments, and XML doc comments on lowered types, members, fields, and statements are emitted as Lua -- comments near the corresponding generated code.
SharpForge emits only helpers needed by the lowered code. List<T> uses a compact Lua table with helper functions for add, count, indexing, iteration, and sorting. These are not full .NET collection surfaces translated into Lua.
That bias keeps output small and predictable: use platform functions directly, model only what the generated Lua needs, and avoid a broad compatibility runtime.
sf-transpile only emits Lua. It does not mutate .w3x files.
sf-build owns Lua dependency bundling and map injection. The separation keeps the C# compiler path independent from MPQ/archive work.
See docs/api/ for complete documentation of every supported language construct and how it lowers to Lua.