using System.Globalization;
public class MyFunctions : ScriptObject
public static uint ParseHex(string text)
if (text.StartsWith("0x"))
text = text.Substring(2);
return uint.Parse(text, NumberStyles.HexNumber);
public static class Program
public const string TemplateText = """
uint16_t {{device.name | string.pad_right 25 }} = 0x{{ device.address | parse_hex | math.format "X8"}};
public static void Main()
var dataObject = new ScriptObject();
dataObject.Import(typeof(MyFunctions));
dataObject.Add("device", new ScriptObject() {
{ "address", "0x50060800" },
var context = new TemplateContext();
context.PushGlobal(dataObject);
var template = Template.Parse(TemplateText);
Console.WriteLine(template.Render(context));