How to use other language libraries/frameworks with lua? [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I really like Lua. It's like javascript without so many warts.
One thing I hate about Lua is the 3rd party support. Good luck finding any industrial-grade libraries or frameworks with Lua scripting - Unity 3d has javascript, but no Lua. Qt the same.
I'm wondering if there is a way to "bridge" an arbirtary Lua & some other application. Say, I want 2 programs running - Lua interpreter which handles all the fun stuff, and Java VM which recieves GUI information from Lua (and displays a Swing GUI) and sends user input to Lua.
EDIT: For clarification what I really really want.
From what I remember from CS101, every program has a standard input and output. Is it possible to have:
- Two programs running, 1st in the foreground (java VM), 2nd in background (lua interpreter). I mean, the 2nd one doesn't appear in the task bar. I'm not sure if that's possible, I'm no systems programmer :).
- Java stdin: gui description data + say, glCanvas or some other graphics data. Stdout: user input. Lua's stdin is joined with Java's stdout and vice versa.
I would thank for a code sample if possible.
EDIT: Nevermind, what I looked for was Inter Process Communication.

You can embed, for example, LuaJ in your Java app. Then you will be able to write any logic on Lua and some other things on Java.
Also, you can take a look on projects like kahlua and mochalua (both hosts on googlecode).

Related

Execute interactive CLI appilcation from C/C++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Java has support for java.lang.Process. This can be used with java.lang.ProcessBuilder or Runtime.exec. With object of java.lang.Process. I can interactive with underlying application by reading output stream/error stream and writing to output stream.
Is there any way/library to do similar thing in either c or c++?
I try popen, but it is unidirectional, i.e. either I can write or read, can't do both.
Any suggestions are welcome. If there is not solution but have some work around, it also welcome.
Update: I am looking solution for Linux Platform.
There is no cross-platform way to launch a new process from either C or C++. Every platform will have its own interface to do so, assuming it has a concept of processes.
The two interfaces you're most likely to come across are the Windows CreateProcess and the POSIX fork/exec.
Since you mentioned reading/writing the subprocess's output/input, you'll also need to use the platform's pipe functions: CreatePipe on Windows or pipe on POSIX-compliant platforms.
There are cross-platform wrappers for all of that, such as Boost Process. None are included with the standard library though, so you'll have to build/install them as you would any other third-party library.
If you can use Managed C++ and .NET, you can use System.Diagnostics.Process, which does the same thing as with java.lang.Process.
Input Redirection
Output Redirection
The caveat is that you need to build your binary as a C++/CLI project, and have .NET as a dependency. You can get around this by putting the managed code in a separate utility library.

Linux Deamon in C++ or Java? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have a Windows service written by another developer who no longer works with me. It was written in C# with .NET 4.5 requirements. Our solution is making the move to Linux and the daemon naturally needs to be converted.
My dilemma is what to rewrite it in? C++ or Java? The daemon is not complicated. It's simply a controller for our other applications to ensure if they crash or are killed they are restarted. Aside from that it performs health checks through a named pipe and is controlled via a password protected web socket via a separate management Tomcat web interface and writes all of it to logs.
Please put aside any suggestions of "write in what you're most comfortable with" I have a fair amount of experience and knowledge in both languages, and I'll learn whatever else I need to as I go. My concern is the feasibility and effort to accomplish everything I need. I don't have any particular time constraints, but if one language is a fraction of the time of the other then maybe that's a better solution.
Writing it in Java looks like the easiest solution currently, but writing it in C++ has the advantage of being native no-frills code. However, I haven't ever written any web interface or socket code in C++ before, so I do not know the effort involved with that.
To break down my requirements:
Linux
Web interface for control
Named pipe for communicating with client applications
Existing code needs to be heavily refactored
Is C++ or Java more appropriate?
Edit: added more info
Edit2: I guess I should have mentioned that the code needs to be heavily refactored anyways. It was originally written in such a way that renders it difficult to make changes and additions. So rewriting is a cleaner solution at this point. As I mentioned, it's not a large program. Just a controller service.
Porting the solution to .Net Core may the way to go. It will run on Linux (and Mac for all intents and purposes...) and most of your codebase may need minimal refactoring. The only concern is if .Net Core currently has the features you would need supported in the app. And, .Net Core is still in preview.

interoperability java and c++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i want to write a program in two different languages java and c++ that needs a dynamic and interactive communication between its c++ component and java component.i know there is jni and jna for invoking native methods in java but i do not think this method is appropriate for my purpose.
for example : say a program that its User Interface is written in c++ and other in java, i do not think that communicating these two component can be done through jni and jna. for example Open Office is written in java and c++.
i searched the internet and find some method for Inter-process communication
like shared memory , pipe, signals, Message passing , ... but i don not know that Inter-process communication is what i need. it seems ipc is for communicating software in two different process but my program all is one process(am i right?!)
so my question is : how the programs that its component is written in different language communicate together? and how i can achieve this?
JNI has been exactly created for the purpose that you are describing; why exactly is it not "what you need"?
One other option: message brokers with implementations for different languages, like http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol
But as you are stressing the latency, this might not be for your.

How would I go about converting a string algorithm into actual code? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
For example, say I had the string
hunger > 80 then findFood();
or
distanceTo sun < 30 then moveAwayFrom(sun);
That's not the exact syntax of what I want, but does anyone know a simple way I could make it so that I can pass that onto an entity in a game and they will basically follow that? The only thing that spring to mind at the moment is making a huge block of if statements that parse the given string, but that feels really really ineffecient.
I'd like a second opinion, just to see if I'm overlooking something really simple here :/
Not an easy task! What you are basically saying is that you need to create a language.
This language will describe all possible commands which you will then parse and generate commands from.
Now you might be thinking to yourself "gee, I've never written a language before!". That's where ANTLR comes in. It allows you to write the grammar for your language, and then generate the parser/lexer that you will need to decode the commands. You can get an IDE for working with ANTLER called ANTLRWorks, and you should check out the getting started tutorial. You really will have to get over your "curse" of trouble with wiki pages and dive in here.
Along the way you will probably realize easier or more efficient ways to encode your commands so that you can later decode them. Some possible alternatives are embedding a scripting language which you will use to encode/decode the commands, such as Python, JavaScript, or Lua. I have seen Lua used in games before, you can read their statement on why they are popular in games here. Good luck!

GUI for computer vision app [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'd like some opinions please on a GUI for my computer vision application. I have written an application in C++ using OpenCV which captures video from a high speed camera, carries out some image processing on the images and displays the results to a HighGUI window. I find myself tweaking variables on a regular basis and have therefore decided it would be easier and quicker to tweak those variables using a GUI on the fly. I have a few options:
Create a Java GUI that can talk to my C++ computer vision app using sockets
Integrate my application within a QT GUI
Use native Windows calls (e.g. MFC)
Which do you you guys think is my best option, bearing in mind that the GUI or sockets must not detract from the performance of the image processing part of the application?
(My target OS is Windows)
Many thanks in advance everyone for your inputs.
I would consider option 1 or 2, 3 seams definitely the worst, because you have to write all related to gui code on your own and it will be not portable.
1. Instead of this option i would consider creating GUI in Java and putting whole c++ code into library and using it in Java or even using native c++ code in Java. This solution should be faster than sending data via sockets.
2. QT seams the best option - it has big community, lot of tutorials and partially is integrated with OpenCV(http://opencv.willowgarage.com/documentation/cpp/highgui_qt_new_functions.html). Another advantage is that application created with QT and OpenCV should run on many operation systems. Also you may use Qt Creator or visual studio qt plugin to create gui.
You really don't want to deal with platform native code on Windows. The API is archaic, just like MFC is.
I don't think there's any benefit to isolating the GUI in a separate process.
I'd suggest using Qt Quick. You can very efficiently display images from OpenCV by binding them to a texture on a trivial scene graph item. You get a fluid, modern user interface and performant integration with OpenCV at the same time. It all blends, so to speak.
The easiest way to integrate your variables with QML is by using model-view paradigm. You can expose the variables form C++ by reimplementing a QAbstractListModel. The variable's value could be bound to the edit and display roles. The variable's name can be exposed as an additional role, called for example name. It's then a simple matter to use a ListView in Qt Quick to display the variable list and allow it to be tweaked at runtime. You can easily have "fancy" delegates for your items, say sliders.

Categories

Resources