I'm trying to write a large scale project in Java/Scala(a JVM language) that extends a preexisting program, but the problem is that the API is written in Lua.
I have found a list of websites that claim to be able to access Java from Lua and Lua from Java:
http://www.keplerproject.org/luajava/
http://code.google.com/p/jnlua/
https://www.github.com/dafrito/jna-lua
The program in which my project is extending, works by loading a certain script within a file. Instead, I want to run everything from a JVM project.
In other works: I need to be able to call functions within a Lua file that is loaded via a reflection-like system from a java project.
Has anyone done something like this before? Is it possible? Would you recommend a certain library for Java <-> Lua connection? Would you recommend an alternative?
Thank you for your time!
You might try LuaJ or Kahlua. I have used both, and they work. LuaJava works as well as jnlua. I know projects using both though I don't myself.
So you have 4 to pick from. There isn't a "best" one, each one has some pluses and minuses. It really depends on what you want to do.
Related
I am working on a C/C++ project.
I found online some very valuable assets in form of Java libraries that I would like to integrate into my C/C++ project. These are big projects I wouldn't consider porting to C/C++.
I read in a Stackoverflow post that Java code can be compiled to native code, thus one would be able to run a Java project without having a Java Virtual Machine in the middle. I found also that there is even a commercial tool for doing this called ExcelsiorJET thus making me believe even more that this could be a reliable thing.
Taking 1, 2 & 3 into consideration I wondered whether or not, one could take a Java library, compile it into a native library and then create a C or C++ wrapper on top of that library. This means that this way the Java Virtual Machine will not be needed anymore. This way I will get rid of the Java Virtual Machine layer. Could this be possible?
I searched online to see if someone had ever successfully created this kind of a pipeline, but couldn't get to a conclusion...
What I would like to ask is whether or not this pipeline could be possible, at least in theory if there are no online examples of people successfully creating it.
If this is possible could anyone point me in the right direction?
Have a look at JNI and the JVM startup sequence: it's all C/C++ coding at this level.
You can either compile java ahead of time (AOT) or you can call the JVM as if it was a library (this is how executable wrappers like Launch4j work).
One way to simplify Java/C/C++ interfacing is to use IDL. Once you have defined your IDL interface it can be used to generate Java/C/C++ code.
I have a Java GUI application that has been interacting quite nicely with a standard C++ based DLL on the back end via SWIG-generated files. The back end program is currently a combination of C++ and managed C++/CLI. The problem is that we may eventually port all of it to C++/CLI.
Please correct me if I'm wrong, but from what I've been able to tell, SWIG currently doesn't work with C++/CLI and there are no plans to make it do so. I imagine that I could do write JNI code to make it work. But using SWIG was a whole lot easier. So what other options are there? The simpler to use, the better.
It is not correct to say that SWIG won't work with C++/CLI... You should be able to use the generated interop stubs exactly the same way you did. I didn't encounter a scenario where switching on the CLR support broke existing well formed C++ code...
I'm thinking about trying to convert a Scons (Python) script to another build system but was wondering if there was a Python-analysis library available in order to 'interrogate' the Scons/Python script?
What I'm [possibly] after is something along the lines of Java's reflection mechanism, in fact, if this is possible via say Jython/Java, coding in Java, that would be best for me as a Java dev (I have no real background in Python).
What I need to be able to do is extract the variable assigment values etc. for certain named class types and methods within the script, so that I can transfer them to my new output format.
Any ideas?
Thanks
Rich
If your current scons files are very regular and consistent it may be easier to do something "dumb" with standard text-editing tools. If you want to get smarter, you should notice that scons is itself a Python program, and it loads your build files which are also Python. So you could make your own "special" version of scons which implements the functions your build scripts use (to add programs, libraries, whatever). Then you could run your build scripts in your "fake" scons program and have your functions dump their arguments in a format suitable for your new build system.
In other words, don't think of the problem in terms of analyzing the Python grammar completely--realize that you can actually run your build scripts as Python code and hijack their behavior.
Easier said than done, I'm sure.
I doubt it's the best tool for migrating scons, but python's inspect module offers some reflection facilities. For the rest, you can simply poke inside live classes and objects: Python has some data hiding but does not enforce access restrictions.
I need to get control over Windows of WindowsXP using Java code,
I need to click/type on particular button/textfield of given window of windowsXP,
How to do this any idea?
Approaches I tried are:
(1) I Tried AutoIT framework, but its Java Wrapper is buggy.. not stable.
(2) JNA can be used for native interfacing, by using some .dll file
to achieve the same. But I don't know which .dll file is used by windowsXP.
Can anybody elaborate on this?
I've not much idea which is much better solution.
Is there any better framework available for such thing.
Thanks.
WindowsXP uses multiple dll files, not one, and studying its API will tell you which one has which functions, and then you can use this information in your JNA interaction code. BTW, I have use AutoIt by itself to help do what you're trying to do and it works fine, and is easier than Java with JNA since it's built for this sort of thing. I've also used AutoIt with Java by having Java call small AutoIt programs and get some simple interaction via standard input and output streams taking care though of the tips and traps in this great article: When Runtime.exec() won't
First, I have no experience doing this. But like the beginning of any good program, I have problem that I need to fix, so I'm willing to learn.
So many of you are probably already familiar with pdftk, the handy utility for handling various pdf-related tasks. So far as I can tell, most of these features are available in much newer, lighter libraries/extensions, except the one I need (and probably the only reason it still exists): merging form data files (fdf and xfdf) with a form PDF and getting a new file as the output.
The problem is that my server doesn't have gcj, which is fundamental to build/compile pdftk. I don't know if it's because I'm on Solaris or if it's for some other sysadmin-level reason, but I'm not getting gcj anytime soon. And there are no pre-compiled binaries for Solaris as far as I can find.
So I'm thinking that the MAKE file and C code can be rewritten to import the Java library (very ancient version of itext) directly, via javac.
But I'm not sure where to really start. All I know is:
I want a binary when I'm done, so that there won't be a need for a Java VM on every use.
The current app uses GCJ.
So my first thought was "Oh this is easy, I can probably just call the classes with some other C-based method", but instead of finding a simple method for doing this, I'm finding tons of lengthy posts on the various angles that this can be approached, etc.
Then I found a page on Sun's site on how to call other languages (like C) in a Java class. But the problems with that approach are:
I'd have to write a wrapper for the wrapper
I'd probably be better off skipping that part and writing the whole thing in Java
I ain't ready for that just yet if I can just import the classes with what is already there
I'm not clear on if I can compile and get a binary at the end or if I'm trapped in Java being needed every time.
Again, I apologize for my ignorance. I just need some advice and examples of how one would replace GCJ dependent C code with something that works directly with Java.
And of course if I'm asking one of those "if we could do that, we'd be rich already" type questions, let me know.
I'm not sure what you are looking for exactly, so I provided several answers.
If you have java code that needs to run, you must:
Run it in a jvm. You can start that vm within your own custom c-code, but it is still using a jvm
Rewrite it in another language.
Compile with an ahead-of-time compiler (eg gcj)
Incidentally, you could compile a copy of gcj in your home folder and use that. I believe the magic switch is --enable-languages=java,c (see: here for more)
If you have c-code you want to call from java, you have four options:
Java Native Interface (JNI). It seems you found this
Java Native Access (JNA). This is slower than JNI, but requires less coding and no wrapper c-code. It does require a jar and a library
Create a CLI utility and use Runtime.Exec(...) to call it.
Use some sort of Inter Process Communication to have the Java code ask the c-code to perform the operation and return the result.
Additional platform dependent options
Use JACOB (win32 only: com access)
I am not sure if I understand what you are looking for.
If you are looking to incorporate the C code into Java to make a native binary without the gcj, I think you are out of luck. You can include the C in Java, but it would be a primarily Java program meaning you would need the JVM on each run. Is there anything stopping you from compiling the gcj yourself?