Giter Club home page Giter Club logo

topaz's People

Contributors

koculu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

topaz's Issues

[Enhancement] .NET Standard 2.1

What kind of enhancement you would like to have? Please describe.
The target .NET framework (6 and 7) are not supported in an environment like Unity3D.

Describe the enhancement you'd like
Would it be possible to target something like .NET Standard 2.1? This would make it possible to use in Unity3D as well as increase the portability of Topaz. I genuinely don't know if this is a small or a huge effort.

Thank you

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

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.

Web API support?

Hi Koculu,
First congrats on this amazing project! I guess this is the first issue/question on this new project.
So my questions are:
Does topaz support Web API like setTimeout, Workers out of the box?
If not, does it have any infrastructure for implementing them?

Thank you!

How i can pass delegate to SetValue?

In Jint i can make something like this:

_engine.SetValue("print", (text)=>{Console.WriteLine(text);});

Is there any way to make something like this in Topaz? I get a Tenray.Topaz.TopazException: Constructor call on null is not defined. when i try to pass a delegate to engine.SetValue()

[Feature Request] Followup to 18: hasOwnProperty

Describe the bug
The example I had shown you in #18 works, but hasOwnProperty is still missing functionality. In JavaScript, hasOwnProperty works on any object, no matter what it is.

Expected behavior
hasOwnProperty should work for any object, regardless if it implements ConcurrentJsObject.cs or IDictionary or something else. To do this it may even utilize reflection if it has to.

Reproduction
Given a class like

public class TestDto
{
    public int SomeProperty { get; set; }
}

running the following code should return true

var engine = new TopazEngine();
var someObject = new TestDto { SomeProperty = 123 };

engine.SetValue("ob", someObject);

var result = engine.ExecuteExpression("ob.hasOwnProperty('SomeProperty')");
Console.WriteLine(result);

Desktop

  • Operating System: Windows 11
  • Topaz Version: 1.3.7

[BUG] Generic ValueTasks<> are not awaitable.

Describe the bug
Generic ValueTasks<> are not awaitable.

To Reproduce
Write a script that awaits a generic ValueTask.

Expected behavior
Returned value should be the result of the ValueTask.

Can I use this repo to run some Node.JS call npm package?

Hello:
I want to know if I can use this repo to call some JavaScript in Node.JS.
There is one Node.JS package CCXT, current version is: 2.0.84, its web version can be found here: https://cdn.jsdelivr.net/npm/[email protected]/dist/ccxt.browser.js

I have the following short Node.JS code to use this package:
D:\nodejs\CCXT_Markets>type ccxt_all_exchanges.js
'use strict';
const ccxt = require('ccxt');
console.log(ccxt.version);
var all_exchanges = ccxt.exchanges
console.log(all_exchanges)
D:\nodejs\CCXT_Markets>
To run this, try this command:
D:\nodejs\CCXT_Markets>node ccxt_all_exchanges.js
2.0.84
[
'aax', 'alpaca', 'ascendex',
'bequant', 'bibox', 'bigone',
'binance', 'binancecoinm', 'binanceus',
'binanceusdm', 'bit2c', 'bitbank',
'bitbay', 'bitbns', 'bitcoincom',
'bitfinex', 'bitfinex2', 'bitflyer',
'bitforex', 'bitget', 'bithumb',
'bitmart', 'bitmex', 'bitopro',
'bitpanda', 'bitrue', 'bitso',
'bitstamp', 'bitstamp1', 'bittrex',
'bitvavo', 'bkex', 'bl3p',
'blockchaincom', 'btcalpha', 'btcbox',
'btcex', 'btcmarkets', 'btctradeua',
'btcturk', 'buda', 'bw',
'bybit', 'bytetrade', 'cex',
'coinbase', 'coinbaseprime', 'coinbasepro',
'coincheck', 'coinex', 'coinfalcon',
'coinmate', 'coinone', 'coinspot',
'crex24', 'cryptocom', 'currencycom',
'delta', 'deribit', 'digifinex',
'exmo', 'flowbtc', 'fmfwio',
'ftx', 'ftxus', 'gate',
'gateio', 'gemini', 'hitbtc',
'hitbtc3', 'hollaex', 'huobi',
'huobijp', 'huobipro', 'idex',
'independentreserve', 'indodax', 'itbit',
'kraken', 'kucoin', 'kucoinfutures',
'kuna', 'latoken', 'lbank',
'lbank2', 'liquid', 'luno',
'lykke', 'mercado', 'mexc',
'mexc3', 'ndax', 'novadax',
'oceanex', 'okcoin', 'okex',
'okex5', 'okx', 'paymium',
'phemex',
... 20 more items
]

I want to know if I can use this repo to run the JavaScript, but return the exchange names to one big string to C#, so I can use Newtonsoft to parse the Json format data.
Remember that console.log shows only the first 100 items, there are still 20 more items are hiding from displaying.

Then, if this is possible, then can I can go one step further, to call the following Node.JS script with Async function and pass 2 parameters.

D:\nodejs\CCXT_Markets>type ccxt_exchange1_markets.js
'use strict';
const ccxt = require('ccxt');
console.log(ccxt.version);
const [nodejs, script1, exchange1, ticker1] = process.argv;

(async function ()
{
let exchange = new ccxt[exchange1];
await exchange.loadMarkets();
console.log(exchange.id);
let ticker_data = await exchange.fetchTicker(ticker1);
console.log (ticker_data)
}) ();

To use the script, pass 2 parameters, one is exchange name, as appeared in the first script, pick any one from the 120 items shown above; the second parameter is one crypto-currency name, like: BTC/USDT.
The following is one example how to use the Node.JS code:
D:\nodejs\CCXT_Markets>node ccxt_exchange1_markets.js binance BTC/USDT
2.0.84
(node:27588) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use node --trace-warnings ... to show where the warning was created)
binance
{
symbol: 'BTC/USDT',
timestamp: 1667060872005,
datetime: '2022-10-29T16:27:52.005Z',
high: 21085,
low: 20542,
bid: 20873.4,
bidVolume: 0.12873,
ask: 20874.33,
askVolume: 0.00239,
vwap: 20756.97674033,
open: 20703.87,
close: 20874.96,
last: 20874.96,
previousClose: 20705.51,
change: 171.09,
percentage: 0.826,
average: 20789.415,
baseVolume: 255975.92477,
quoteVolume: 5313286316.535715,
info: {
symbol: 'BTCUSDT',
priceChange: '171.09000000',
priceChangePercent: '0.826',
weightedAvgPrice: '20756.97674033',
prevClosePrice: '20705.51000000',
lastPrice: '20874.96000000',
lastQty: '0.00285000',
bidPrice: '20873.40000000',
bidQty: '0.12873000',
askPrice: '20874.33000000',
askQty: '0.00239000',
openPrice: '20703.87000000',
highPrice: '21085.00000000',
lowPrice: '20542.00000000',
volume: '255975.92477000',
quoteVolume: '5313286316.53571490',
openTime: '1666974472005',
closeTime: '1667060872005',
firstId: '2046781999',
lastId: '2052933889',
count: '6151891'
}
}

D:\nodejs\CCXT_Markets>

Let me know if I can use the repo to run the above Node.JS scripts, if yes, please share some codes. I am using Visual Studio 2022 on Windows 10.
Please advise,
Thanks,

[FEATURE] Add custom awaiter to support IL2CPP

Is your feature request related to a problem? Please describe.
IL2CPP does not support dynamic await statements and application crashes.

Describe the solution you'd like
Add an interface to customize await behavior.

[Feature Request] System.Text.Json.JsonObject is not supported

Describe the bug
Using Topaz with System.Text.Json namespace types like JsonValue/JsonArray/JsonObject doesn't work as of now. When testing with JsonObject I didn't get an error, but also didn't get the right result.

Expected behavior
The code below should return 123, but returns null instead.

To Reproduce

var engine = new TopazEngine();

// JsonObject does not work
var jObject = (JsonObject)JsonObject.Parse("""
    { "a": {"b": "123" }}
    """);

// TestDto does work
//var jObject = new TestDto();

engine.SetValue("ob", jObject);

var result = engine.ExecuteExpression("ob.a.b");
Console.WriteLine($"'{result}'");

public class TestDto
{
    public TestAnotherDto a { get; set; } = new TestAnotherDto { b = 123 };
}

public class TestAnotherDto
{
    public int b { get; set; }
}

Desktop

  • Operating System: Windows
  • Topaz Version: 1.3.6

[FEATURE] The `arguments` object is not supported inside functions

Hello, Ahmed!

Currently, inside the functions are not supported the arguments object (as in principle and the this keyword). For example, now it is impossible to execute such a JS code:

function sum() {
    var result = 0,
        argumentIndex,
        argumentCount = arguments.length
        ;

    for (argumentIndex = 0; argumentIndex < argumentCount; argumentIndex++) {
        result += arguments[argumentIndex];
    }

    return result;
}

sum(120, 5, 18, 63);

Concurrent Execution Question

First of all, thank you for sharing your project!

Preface: I'm probably doing something wrong.

In regards to concurrent execution, I've tried this out in a game client I'm writing where a Topaz script is executed as a command in a client WPF application. It works, there's no blocking on the UI and the scripts are running. But, if I execute two commands concurrently, the first topaz script stops execution when the 2nd is run, and then when the 2nd is over it picks up on the 1st one again where it stopped. I might expect that if I used the same TopazEngine object but I created a new one with each execution (thinking they would be independent of each other). The script below counts from 0 to 9 with a 1 second pause each loop.

  public override void Execute()
  {
      var engine = new TopazEngine();
      engine.AddType(typeof(TerminalScriptCommands), "Terminal");
      engine.ExecuteScript(@"
      for (var i = 0; i < 10; i++)
      {
          Terminal.Send(""say "" + i)
          await Terminal.Pause(1000)
      }");
  }

Is it possible for two TopazEngine executes to run at the same time without one halting execution of the other?

I'll include the Pause function also in case anything it's doing might be a contributing factor (this pause function is one I've used with Moonsharp Lua/NLua in the past).

  public static void Pause(int milliseconds)
  {
      DispatcherFrame df = new DispatcherFrame();
  
      new Thread(() =>
      {
          Thread.Sleep(TimeSpan.FromMilliseconds(milliseconds));
          df.Continue = false;
  
      }).Start();
  
      Dispatcher.PushFrame(df);
  }

Support for hasOwnProperty

Describe the bug
It seems that hasOwnProperty is not supported by Topaz.

Is there an option or something to support hasOwnProperty?

To Reproduce

var engine = new TopazEngine();
engine.ExecuteScript("""let ob =  { "a": {"b": "123" }};""");
var result = engine.ExecuteExpression("ob['a'].hasOwnProperty('b')");
Console.WriteLine(result);

Expected behavior
Test code should print "true". Instead, it crashes.

Tenray.Topaz.TopazException: 'Function ob.a.hasOwnProperty is not defined.'
   at Tenray.Topaz.ErrorHandling.Exceptions.ThrowFunctionIsNotDefined(Object callee, ScriptExecutor scope)
   at Tenray.Topaz.Core.ScriptExecutor.CallFunction(Object callee, IReadOnlyList`1 args, Boolean optional, CancellationToken token)
   at Tenray.Topaz.Expressions.CallExpressionHandler.Execute(ScriptExecutor scriptExecutor, Node expression, CancellationToken token)
   at Tenray.Topaz.Core.ScriptExecutor.ExecuteStatement(Node statement, CancellationToken token)
   at Tenray.Topaz.Core.ScriptExecutor.ExecuteExpressionAndGetValue(Expression expression, CancellationToken token)
   at Tenray.Topaz.Core.ScriptExecutor.Tenray.Topaz.ITopazEngineScope.ExecuteExpression(String code, CancellationToken token)
   at Tenray.Topaz.TopazEngine.ExecuteExpression(String code, CancellationToken token)
   at Program.<Main>$(String[] args) in C:\Users\rtda\source\repos\ConsoleApp7\ConsoleApp7\Program.cs:line 26

Desktop:

  • Operating System: Windows
  • Topaz Version: 1.3.6

Why not using Esprima from nuget

Hi, thanks for the amazing project it looks amazing, and probably it will suit me needs perfectly.

I was just wondering why use a "hard copy" of Esprima instead of using the Nuget version which is more up to date (for example it got updated just yesterday).

Again thanks for the project, will try my best to help you if i find something that needs fixing/improvement.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.