Skip to content
Open
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
19 changes: 16 additions & 3 deletions src/BizHawk.Client.Common/lua/LuaDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Linq;
using System.Reflection;
using System.Text;

using BizHawk.Common.ReflectionExtensions;

using Newtonsoft.Json;

namespace BizHawk.Client.Common
Expand All @@ -27,7 +30,7 @@ public string ToTASVideosWikiMarkup()
** Brackets around a parameter indicate that the parameter is optional. Optional parameters have an equals sign followed by the value that will be used if no value is supplied.
** Brackets after a parameter type indicate it is an array
* ? (question mark)
** A question mark next to a value indicates that it is nullable i.e. null/nil may be passed instead of a real value. (Confusingly, many .NET types are nullable but omit the '?'. These aren't common in our Lua APIs.)
** A question mark next to a value indicates that it is nullable i.e. null/nil may be passed instead of a real value.
* null/nil
** null is equivalent to Lua's nil.
** Omitting the last parameter is equivalent to passing nil, same with the second-last parameter and so on. However, if you want to pass the last parameter but not one in the middle, you will need to explicitly pass nil.
Expand Down Expand Up @@ -253,7 +256,12 @@ static string DisplayDefaultValue(object/*?*/ defaultValue)
list.Append('(');
foreach (var (i, pi) in parameters.Index())
{
var p = TypeCleanup(pi.ParameterType);
var pType = pi.ParameterType;
var p = pi.IsNRTOrNullableT() ?? true
? TypeCleanup(pType.IsValueType
? pType.GenericTypeArguments[0] // unwrap `Nullable<>`
: pType) + "?"
: TypeCleanup(pType);
if (pi.GetCustomAttribute<LuaColorParamAttribute>() is not null) p = p.Replace("object", "luacolor");
if (pi.GetCustomAttribute<LuaZeroIndexedAttribute>() is not null) p = p.Replace("nluatable", "nluatable0Indexed");
p += $" {pi.Name.ToLowerInvariant()}";
Expand Down Expand Up @@ -316,7 +324,12 @@ public string ReturnType
get
{
if (field is not null) return field;
var returnType = TypeCleanup(Method.ReturnType).Trim();
var rType = Method.ReturnType;
var returnType = rType.IsValueType
? rType.IsNullableT()
? TypeCleanup(rType.GenericTypeArguments[0]) + "?" // unwrap `Nullable<>`
: TypeCleanup(rType)
: TypeCleanup(rType) + "?"; //TODO read NRT metadata, see existing methods in `ReflectionExtensions`
if (Method.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(LuaZeroIndexedAttribute), inherit: false).Length is not 0)
{
returnType = returnType.Replace("nluatable", "nluatable0Indexed");
Expand Down
Loading