Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registrable generators: add support for lua, python #1808

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace CppSharp.Generators.Registrable.Lua.Sol
{
public class LuaSolGenerationContext : RegistrableGeneratorContext
{
public LuaSolGenerationContext()
: base()
{
}
}
}
30 changes: 30 additions & 0 deletions src/Generator/Generators/Registrable/Lua/Sol/LuaSolGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using CppSharp.AST;
using System.Collections.Generic;

namespace CppSharp.Generators.Registrable.Lua.Sol
{
public class LuaSolGenerator : RegistrableGenerator<LuaSolGeneratorOptions, LuaSolHeaders, LuaSolSources>
{
public const string Id = "Lua::Sol";
public static readonly GeneratorKind Kind = new(Id, "lua::sol", typeof(LuaSolGenerator), typeof(LuaSolTypePrinter), new[] { "lua::sol" });

public LuaSolGenerator(BindingContext context) : base(context)
{
}

protected override LuaSolGeneratorOptions CreateOptions()
{
return new LuaSolGeneratorOptions(this);
}

protected override LuaSolHeaders CreateHeader(IEnumerable<TranslationUnit> units)
{
return new LuaSolHeaders(this, units);
}

protected override LuaSolSources CreateSource(IEnumerable<TranslationUnit> units)
{
return new LuaSolSources(this, units);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace CppSharp.Generators.Registrable.Lua.Sol
{
public class LuaSolGeneratorOptions : TRegistrableGeneratorOptions<LuaSolGenerator>
{
public LuaSolNamingStrategy NamingStrategy;

public LuaSolGeneratorOptions(LuaSolGenerator generator) : base(generator)
{
NamingStrategy = new LuaSolNamingStrategy(generator);
}

public override string DefaultRootContextType => "::sol::state_view&";

public override string DefaultRootContextName => "state";

public override string DefaultTemplateContextDefaultType => "::sol::table";

public override string DefaultTemplateContextDefaultValue => "::sol::nil";

public override string DefaultCmakeVariableHeader => "LUA_SOL_BINDINGS_HEADER";

public override string DefaultCmakeVariableSource => "LUA_SOL_BINDINGS_SOURCE";
}
}
82 changes: 82 additions & 0 deletions src/Generator/Generators/Registrable/Lua/Sol/LuaSolHeaders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System.Collections.Generic;
using CppSharp.AST;

namespace CppSharp.Generators.Registrable.Lua.Sol
{
public class LuaSolHeaders : LuaSolSources
{
public LuaSolHeaders(LuaSolGenerator generator, IEnumerable<TranslationUnit> units)
: base(generator, units)
{
}

public override string FileExtension => "h";

protected override bool TemplateAllowed { get { return true; } }

public override void Process()
{
GenerateFilePreamble(CommentKind.BCPL);

PushBlock();
WriteLine("#pragma once");
PopBlock(NewLineKind.BeforeNextBlock);

TranslationUnit.Visit(this);
}

#region TranslationUnit

public virtual void GenerateTranslationUnitRegistrationFunctionDeclaration(TranslationUnit translationUnit)
{
NewLine();
GenerateTranslationUnitRegistrationFunctionSignature(translationUnit);
WriteLine(";");
NewLine();
}

public override void GenerateTranslationUnit(TranslationUnit translationUnit)
{
GenerateTranslationUnitNamespaceBegin(translationUnit);
GenerateTranslationUnitRegistrationFunctionBody(translationUnit);
GenerateTranslationUnitRegistrationFunctionDeclaration(translationUnit);
GenerateTranslationUnitNamespaceEnd(translationUnit);
}

public override bool CanGenerateTranslationUnit(TranslationUnit unit)
{
if (AlreadyVisited(unit))
{
return false;
}
return true;
}

public override bool VisitTranslationUnit(TranslationUnit unit)
{
if (!CanGenerateTranslationUnit(unit))
{
return false;
}

GenerateTranslationUnit(unit);

return true;
}

#endregion

public virtual void GenerateMain()
{
VisitNamespace(TranslationUnit);
}

public virtual void GenerateIncludes()
{
if (Generator.GeneratorOptions.BaseInclude != null)
{
WriteLineIndent(Generator.GeneratorOptions.BaseInclude.ToString());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace CppSharp.Generators.Registrable.Lua.Sol
{
public class LuaSolNamingStrategy : RegistrableNamingStrategy<LuaSolGenerator>
{
public LuaSolNamingStrategy(LuaSolGenerator generator)
: base(generator)
{
}
}
}
Loading