I need to read a python file from javascript. I used in another project RedBaron which was quite helpful since I can easily access different node types and their value. Since I cannot use this library in Javascript since RedBaron is a python library I wanted to ask you all if you know a library that is similar to RedBaron.
Thanks in advance!
I tried using a line by line reader in Javascript but it is not sufficient for my needs. As I explained earlier I want to access different node types their values or operators.
Related
"Tab"ing the REPL gives me a list of functions, but often working with multiple languages, I forget the signature of common functions like fs.open, etc. Is there anyway to show these in the REPL?
Thanks to auto-complete in editors, they seem to be fine. But REPL for writing some quick script, I have pull up the node documentation each time for simple things.
Is there a better way to deal with this?
This semi official project developed under the node umbrella on GitHub offers a few improvement over the default REPL while used interactively:
https://github.com/nodejs/repl
Syntax highlighting is enabled for the input, basic functions signatures are displayed as hints.
As stated in this issue, its future is still uncertain, but it's already quite usable in the current state: https://github.com/nodejs/repl/issues/46
I am currently trying to make JavaScript support for the game "Minecraft" using Nashorn. My goal is to give users the ability to create their own commands and features.
For the most part it is working fine so far but the problem is that Minecraft's code is obfuscated when using it with Forge.
For that reason all field and method calls have to be re-mapped with their corresponding srg names.
Example: mc.thePlayer.swingItem(); to mc.field_71439_g.func_71038_i();
I am able to inject code into the Nashorn library using Mixin and I have already made a parser for the srg file. In a nutshell, what I need is the method I can use to replace thePlayer with field_71439_g or swingItem()V with func_71038_i()V before actually executing the code.
I have already tried finding the proper methods for hours.
https://github.com/CCBlueX/LiquidBounce1.8-Issues/issues/2649
You need MCPbot
Or rather, its mappings exports.
Note that MCPbot, as its name implies, is a bot. Specifically one on an IRC channel so that mod developers can go "hey I figured out what func_12345_a does" and tell the bot, giving it a human-readable name, named parameters, and javadoc and the next build of Forge will include these updated mappings for modders to use.
(The "MCP" part stands for "Minecraft Coder Pack.")
You can find exports of the SRG name mappings on the MCPbot website of which you'll need both csv files: Fields and Methods (as they're exported separately).
I will note, however, that including these mappings in your mod will probably violate copyright and you should check with Prof Mobius before using them in this manner.
Solution
Just inject into this methods of "jdk.internal.dynalink.beans.AbstractJavaLinker"
Remap methods:
addMember(Ljava/lang/String;Ljava/lang/reflect/AccessibleObject;Ljava/util/Map;)V
Remap fields:
addMember(Ljava/lang/String;Ljdk/internal/dynalink/beans/SingleDynamicMethod;Ljava/util/Map;)V
setPropertyGetter(Ljava/lang/String;Ljdk/internal/dynalink/beans/SingleDynamicMethod;Ljdk/internal/dynalink/beans/GuardedInvocationComponent$ValidationType;)V
I was using the esprima AST generator for javascript and using node.js. It works great!
Now I need to process the resultant json and would really like to use groovy - I have used groovy for this very successfully in the past. I could use two passes (first use node to create the json files and then use a groovy script to process them). However, given the large number of files I will be processing it is preferable to me to use groovy entirely.
Does anyone know if a AST generator for javascript is available in either Java or groovy? Google searches were fruitless for me - way too many hits!
[Afterthought: If node.js is callable from groovy, then I would need a really good set of directions on how that might be made to work!]
jade permits you to simply write
include folder/file
to include code from another file.
Is it possible to add simply cut - copy style code from another file in node for javascript files?
Its for development purpose, to isolate some code and work on it seperately.
PS:- I'm aware of require('jsfile.js') and export.x = function(){..
The accepted answer is wrong.
Depending on whether node fs and eval were available at the time this question was written, the accepted answer was probably always wrong.
While not recommended, what you want to do is essentially possible:
Use node's built-in filesystem functions to read the file you want to "copy-paste" into the current file.
Use eval() to "paste" that file into your current file and run it as if it was part of the current file.
https://github.com/dennishall/node-require-without-require
Update 6 Oct 2020: Embarrassingly, the answer I've provided below is false.
I am not certain what were the circumstances for my writings below, as I was familiar with eval at the time (and a very long time before then), however, it is what it is :)
Read the answer that #Dennis wrote for the correct one.
You cannot merge (or include) a script file into another script file during runtime. Utilizing require is your best option to separate your application logic into multiple files.
JavaScript is an object oriented language, and what you are asking for is a solution to a problem that exists in procedural programming languages.
I suggest that you design your application in such a way that would allow you to separate its files into object types that take on different responsibilities instead of treating each file as a script within some global state.
To answer your other question, Jade is actually parsing its source files and therefore can provide its own file merging. If we apply this to our scenario, Jade is to jade source files as V8 is to JavaScript source files. Since the jade language is procedural, it makes sense to allow this kind of feature where in JavaScript (which is object oriented) it doesn't.
I have a simple function written in python which I want to port to javascript.
I have compiled python 2.7 into a .so library, so thats not the issue.
The problem I'm having is that after I compile my program with cython, the function names get all scrambled up, which means I don't know how to preserve the functions when i run emcc.
Does anybody have any experience compiling python programs to js with emscripten?
Any information would be appreciated.
Note: I want to preserve the exact functionality to that of python, I don't want something that translates a python program into javascript.
This other question, with an accepted answer, complains about the same issue: Cython mangling function names and making it difficult to access from C++: Embed python function in C++
The accepted answer states that Cython isn't meant for this sort of thing at all, suggesting you can't do what you want in this fashion:
You're not going to be able to get the interoperation you want that way. If you open and inspect hello.c you won't find "static int say_hello" anywhere in there. Cython is designed for letting Python use C libraries, not letting C libraries use python.
The not-accepted next answer suggest that specifying public will not mangle the function name, although he also mentions linking problems.
# (in the generated C file hello.c)
__PYX_EXTERN_C DL_IMPORT(...) say_hello(...);
Worth a shot, but please consider the other options in the comments if it fails.