public override bool VisitClassDecl(Class @class) { if (@class.IsIncomplete) { return(true); } PushBlock(BlockKind.InternalsClass, @class); var callbacks = new NAPIInvokes(Context); @class.Visit(callbacks); Write(callbacks.Generate()); PopBlock(NewLineKind.BeforeNextBlock); PushBlock(BlockKind.Class, @class); Write($"static napi_value register_class_{GetCIdentifier(Context, @class)}"); WriteLine("(napi_env env)"); WriteOpenBraceAndIndent(); var sources = new NAPIRegisterImpl(Context); sources.Indent(CurrentIndentation); @class.Visit(sources); Write(sources.Generate()); UnindentAndWriteCloseBrace(); PopBlock(NewLineKind.BeforeNextBlock); return(false); }
public override void GenerateFunctionGroup(List <Function> group) { var function = group.First(); if (function.IsOperator) { return; } PushBlock(BlockKind.Function); var callbacks = new NAPIInvokes(Context); callbacks.GenerateFunctionGroup(group); Write(callbacks.Generate()); PopBlock(NewLineKind.BeforeNextBlock); PushBlock(BlockKind.Function); Write($"static napi_value register_function_{GetCIdentifier(Context, function)}"); WriteLine("(napi_env env)"); WriteOpenBraceAndIndent(); WriteLine("napi_status status;"); var qualifiedMethodId = GetCIdentifier(Context, function); var valueId = $"_{qualifiedMethodId}"; WriteLine($"napi_value {valueId};"); var callbackId = $"callback_function_{qualifiedMethodId}"; WriteLine($"status = napi_create_function(env, \"{function.Name}\", NAPI_AUTO_LENGTH, " + $"{callbackId}, 0, &{valueId});"); WriteLine("assert(status == napi_ok);"); NewLine(); WriteLine($"return {valueId};"); UnindentAndWriteCloseBrace(); PopBlock(NewLineKind.BeforeNextBlock); }