koculu / Topaz

Multithreaded Javascript Engine for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE] Create an interface to extract meta information from TopazFunction

VelvetToroyashi opened this issue · comments

Firstly, great project!

Secondly, I want to elaborate on the title by saying that in short what I'm trying to do is invoke a function with an arbitrary amount of parameters.

Given the following:

function myFunc(someParam, otherParam, thirdParam) {}

The return form evaluating this is a TopazFunction, which is an internal type. Technically fine; Topaz lets you pass the object to InvokeFunction, but a slight hindrance for my use-case. I'd personally like a way that functions can be exposed (just so I can see their names and the name of their parameters), and potentially build a delegate without having to do hacky reflection to determine the correct amount of parameters, etc.

Technically speaking yes, as I did mention, but I'm interested in extracting the method name and parameters; working on a bit of a strange project perhaps, basically a command system that links this library with Topaz, allowing for commands to be written in JS, and powered by .NET. While not strictly necessary for the function of my idea, at least getting the name of the function is, as it's necessary for invoking commands from Remora

Please ignore my previous comment which was already deleted before your answer to it :)
This is a good feature request. I will add this as soon as possible.
Thank you.

@VelvetThePanda
Please note that, all Javascript engines and also Topaz is tolerant against not matching arguments.
I believe you shouldn't write any check on argument counts mismatches.

This should be fine; the argument mismatch comment was specifically because of how Topaz handles creating delegates from functions, but now that I can get the information I need (function name, argument names), I can make the requisite shim and just invoke the function, if that makes sense

Great, thanks.!
Dynamic delegate creation is required because:

  • C# is strict on argument count.
  • A topaz function can be converted to a delegate automatically.
    It is required to pass JS functions to the .NET methods with argument types Action<>, Func<> or any kind of delegate.
    You may check DelegateArgumentConversionTests to understand what I mean.