I have a some amount of Java code in my Project (more specificaly GWT)
I have decided to start using react for future features
Now the problem is that i need to access some Java enum in React to perform calls to server from Javascript (or whatever operation)
My questions are
A) Is there a way to access Java public enum values in Js ? If so ...how ?
B) Is there some tool to generate Javascript .js file from these enum and accesss it that way (maybe maven should know this ?)
Any ideas appreciated
If you are using GWT 2.8.0 you can use the newly introduced annotations. There is a very good blog-post about it: here
Related
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.
Is it possible to call Swift functions/callbacks from Javascript ?
In Android it is possible to use JavaVoidCallbacks, is there anything similar in Swift? Right now Im using JavaScriptCore,where i can call javascript functions from Swift.
Yes you can.
Please refer to this Tutorial: https://www.raywenderlich.com/124075/javascriptcore-tutorial
You are interested in the paragraph "Exposing Native Code"
In obj-c is very simple. You can do it just by using your jsContext as a normal dictionary.
context[#"functionName"] = ^ <#returnType#> (<#parameters#>) {
<#Your code#>
}
Hope it helped.
In Swift, the easiest way I found was to create a gateway object in Javascript, using e.g. evaluateScript(), and then adding functions to that object:
// x is JSContext
let gateway = x.objectForKeyedSubscript("gateway" as NSString)
let p: #convention(block) (Int, Double) -> () = { h, ms in
return self.swift_method(h, ms)
}
gateway!.setObject(p, forKeyedSubscript: "swift_method" as NSString)
After that you can call gateway.swift_method() in Javascript.
Most type conversions are automatic. I have used types Int, Double, String and [Int] as parameter and/or return types in the lambda.
I have the same question. When I saw the answers to this Q. I tried to use JavaScriptCore to call Swift methods from the JS side. I could inject Swift or JS methods into JSContext. However, the methods injected into JSContext are not accessible in my case.
I use WKWebView as an HTML viewer in the ViewController in my iOS native app. I use this kind of view controller to present some help information in my app. After several days of struggling, I finally found an alternative way to make Swift and JS interaction happen. The strategy is to use WKScriptMessageHandler as a gateway between Swift and JS. Refer to this good blog on how to do it in detail. Another blog, Using WebKit to call WKWebView JavaScript from Swift and Swift from JavaScript, provides another example case, which is very useful.
From my experience, WKScriptMessageHandler is based on a very elegant structure. Through WKUserContentController, you set up a message gateway between JS and Swift. There is This will allow a JS callback to Swift with messages. A delegate of WKWebViewConfiguration has to be implemented, my view controller with web view, or my custom class, to receive JS message calls with data. The message can take a JSON string as a parameter to pass data. On the Swift side, by using a similar JSContext syntax like evaluateJavaScript to specify JS a function with data.
By the way, I was told that in my case, JavaScriptCore is based on Java virtue machine. There may be performance issue and may pose a security risk. Apple has disabled the feature of JavaScriptCore in WKWebView.
The Xcode in my case is Version 13.4, and Swift is 5.
I have written a blog on this: Build a Bridge between Swift and JS
There is a built in function from the Microsoft.VisualBasic assembly.
I can use it in VB like this:
APR = (Rate(TotPmts, -Payment, PVal, FVal, PayType, Guess) * 12) * 100
My current project is in Java or Javascript and I need to use this function.
Answers on the web say just add the namespace and assembly and use the same in Java or Javascript
So how can I use use Financial.
Rate in Java (or perhaps even porting the source code to it)?
Thanks for any help.
In a C# project(or other .NET projects), just simply add Microsoft.VisualBasic.dll as a reference into your project, you can use Financial.Rate in your code, don't forget to add the namespace using Microsoft.VisualBasic; It's very easy because all .NET languages (C#/VB/etc) uses the CIL (Common Intermediate Language), so the .dll files compiled from different languages can be shared.
In a Java project, things are quite different. You need to use JNA(Java Native Access). See JNA.
How can I create a JS library in scala-js? I am using standard Play/Scala server + scala-js client with shared objects. I want my library to be on URI /api/mylib.js.
I don't know how make scala-js client project without main method. Also how to generate scala-js code to the specific URL I need.
To write a JS library, you need to export the public API to JavaScript.
You will also likely want to disable the generation of the "launcher", which looks for a JSApp in your classpath and calls its main method. Otherwise fastOptJS will complain that it cannot find any JSApp. You can do this with the following sbt setting:
persistLauncher := false
Edit: See also the blog post How to make an idiomatic Javascript library with Scala.js
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.