-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a reflection-based documentation generator and partial documentation
- Loading branch information
1 parent
136af1e
commit 1c84f76
Showing
10 changed files
with
455 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace PrincessRTFM.WoLua.Lua.Docs; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.ReturnValue)] | ||
internal class AsLuaTypeAttribute: Attribute { | ||
public string LuaName { get; } | ||
|
||
public AsLuaTypeAttribute(string luaType) { | ||
this.LuaName = luaType; | ||
} | ||
public AsLuaTypeAttribute(LuaType luaType): this(luaType.LuaName()) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace PrincessRTFM.WoLua.Lua.Docs; | ||
|
||
using System; | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.ReturnValue)] | ||
internal class LuaDocAttribute: Attribute { | ||
public string Description { get; private init; } | ||
public string[] Lines => this.Description.Split('\n', StringSplitOptions.TrimEntries); | ||
|
||
public LuaDocAttribute(string help) { | ||
this.Description = help; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
namespace PrincessRTFM.WoLua.Lua.Docs; | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
|
||
using MoonSharp.Interpreter; | ||
|
||
using PrincessRTFM.WoLua.Constants; | ||
|
||
[SuppressMessage("Naming", "CA1720:Identifier contains type name", Justification = "the names are defined externally")] | ||
[Flags] | ||
public enum LuaType: ushort { | ||
Any = 0, | ||
String = 1 << 0, | ||
Boolean = 1 << 1, | ||
Integer = 1 << 2, | ||
Number = 1 << 3, | ||
Table = 1 << 4, | ||
Function = 1 << 5, | ||
Userdata = 1 << 6, | ||
Nil = 1 << 7, | ||
} | ||
|
||
public static class LuaTypeExtensions { | ||
public static string LuaName(this LuaType type) { | ||
return type is LuaType.Any | ||
? type.ToString().ToLower() | ||
: string.Join("|", Enum.GetValues<LuaType>() | ||
.Where(t => t is not LuaType.Any && type.HasFlag(t)) | ||
.OrderBy(t => (ushort)t) | ||
.Select(t => t.ToString().ToLower()) | ||
); | ||
} | ||
public static string LuaName(this LuaType type, string userdataName) { | ||
return type is LuaType.Any | ||
? type.ToString().ToLower() | ||
: string.Join("|", Enum.GetValues<LuaType>() | ||
.Where(t => t is not LuaType.Any && type.HasFlag(t)) | ||
.OrderBy(t => (ushort)t) | ||
.Select(t => t is LuaType.Userdata ? userdataName : t.ToString().ToLower()) | ||
); | ||
} | ||
|
||
public static LuaType FromType(Type originalType) { | ||
LuaType lua = LuaType.Any; | ||
Type realType = originalType; | ||
if (originalType.IsGenericType && realType.GetGenericTypeDefinition() == typeof(Nullable<>)) { | ||
realType = originalType.GenericTypeArguments[0]; | ||
lua = LuaType.Nil; | ||
} | ||
|
||
// apparently you can't do a switch using typeof() cases, so here we fuckin' are | ||
if (realType == typeof(DynValue)) | ||
lua = LuaType.String | LuaType.Boolean | LuaType.Integer | LuaType.Number | LuaType.Table | LuaType.Function | LuaType.Userdata | LuaType.Nil; | ||
else if (realType == typeof(string)) | ||
lua |= LuaType.String; | ||
else if (realType == typeof(bool)) | ||
lua |= LuaType.Boolean; | ||
else if (realType == typeof(byte) || realType == typeof(sbyte)) | ||
lua |= LuaType.Integer; | ||
else if (realType == typeof(short) || realType == typeof(ushort)) | ||
lua |= LuaType.Integer; | ||
else if (realType == typeof(int) || realType == typeof(uint)) | ||
lua |= LuaType.Integer; | ||
else if (realType == typeof(long) || realType == typeof(ulong)) | ||
lua |= LuaType.Integer; | ||
else if (realType == typeof(float) || realType == typeof(double)) | ||
lua |= LuaType.Number; | ||
else if (realType == typeof(Closure) || realType == typeof(CallbackFunction)) | ||
lua |= LuaType.Function; | ||
else if (realType == typeof(Table)) | ||
lua |= LuaType.Table; | ||
else if (realType == typeof(void)) | ||
lua |= LuaType.Nil; | ||
else if (realType.IsAssignableTo(typeof(IEnumerable)) || (realType.IsGenericType && realType.GetGenericTypeDefinition() == typeof(IEnumerable<>))) | ||
lua |= LuaType.Table; | ||
else if (realType.IsAssignableTo(typeof(IDictionary)) || (realType.IsGenericType && realType.GetGenericTypeDefinition() == typeof(IDictionary<,>))) | ||
lua |= LuaType.Table; | ||
else | ||
lua |= LuaType.Userdata; | ||
|
||
return lua; | ||
} | ||
} |
Oops, something went wrong.