Need some direction on macros.

2022-08-19 Thread ggibson
I once had to overcome the same thing for scraping a site that used a rotating cipher of obfuscating links through various js schemes. My solution was overkill, but future proof - embed the entire v8 js engine, evaluate the code, then extract what was necessary. It's an option. This was before d

Need some direction on macros.

2022-08-19 Thread mratsim
Have you checked yt-dlp source code in case they already solved that?

Need some direction on macros.

2022-08-19 Thread jyapayne
It sounds like you're in for a world of pain and/or fun :) Writing an interpreter is no joke, and it looks like you may need to account for complex behavior that has already been done by someone else. Might I suggest using an already made Javascript interpreter and see if that works for you? [D

Need some direction on macros.

2022-08-19 Thread xioren
Yeah I guess and interpreter is my next focus.

Need some direction on macros.

2022-08-19 Thread xioren
Yeah makes sense. Good explanation.

Need some direction on macros.

2022-08-19 Thread xioren
Unfortunately it's more complex than that. Here is the rube goldberg code I need to convert to Nim. These are steps operating on an array. (youtubes anti-piracy measure) try{try{4=c[62-Math.pow(3,3)%497]&&(c[33]>30*Math.pow(2,1)-53||((0,c[44])(c[0]),void 0))&&(0,c[56])(c[0]),1=c[1

Need some direction on macros.

2022-08-19 Thread Hlaaftana
Since you want to convert the javascript to nim I assume you want to use symbols defined in javascript in nim. This is impractical unless you use nimscript somehow, but if you just want to run javascript, you can bind to [QuickJS](https://bellard.org/quickjs/), there is a [wrapper for it alread

Need some direction on macros.

2022-08-19 Thread PMunch
The power of macros is exactly what you seem to perceive as a weakness. Most languages doesn't allow you to modify your own code on compile-time, some offer limited support. Nim is really one of the few languages which offers this level of compile-time modification of code, which is a really pow

Need some direction on macros.

2022-08-19 Thread Vindaar
Well, at least if it's only math expressions you need to evaluate, you may be in luck, as there's already a small expression evaluator by Yardanico:

Need some direction on macros.

2022-08-19 Thread pp
If you know the js code only at runtime seems like you need to have/write an interpreter...

Need some direction on macros.

2022-08-18 Thread xioren
Yeah your right, that limitation makes sense. I guess it's just shocking to learn given my (incorrect) assumptions of what macros were capable of.

Need some direction on macros.

2022-08-18 Thread ElegantBeef
You could look at embedding the NimVM but that's a big dependency for something like this. It's not that remarkable of a limitation though, Nim is a compiled program you cant exactly have new generated native code at runtime without a bunch of hassle.

Need some direction on macros.

2022-08-18 Thread xioren
If I understand it correctly static means known at compile time. Problem is these strings are NOT known at compile time. Is there a way to use macros dynamically?

Need some direction on macros.

2022-08-18 Thread xioren
One thing...I get this compile error when trying to run the code like so: let x = "1+1" echo nimify(x) /home/xioren/Documents/coding/nim/burner.nim(190, 12) Error: type mismatch: got but expected one of: macro nimify(s: static string): untyped first type m

Need some direction on macros.

2022-08-18 Thread ElegantBeef
`let` is a runtime variable, macros do not run at runtime. If you need runtime support you need to make a math evaluator and parse/evaluate it there.

Need some direction on macros.

2022-08-18 Thread xioren
Hey that's more than I was hoping for. Thank you! I've been pulling my hair out with this thing.

Need some direction on macros.

2022-08-18 Thread ElegantBeef
To do this you'd need to make a macro that takes a `static string` and operates on it. I have no clue the requirements of what you're after, but I've written a very simple 'parser' that simply inserts spaces between operators where it makes sense then uses Nim's `parseExpr` to just get Nim to ha

Need some direction on macros.

2022-08-18 Thread xioren
I have a situation where I need to parse "compiled" javascript and execute equivalent code in Nim. I assume macros are the best (only?) way to achieve this. I have read all Macro resources + the Nim sections from Araq's book and I still don't have a clue where to begin; maybe I'm just a moron. I