Reading from keyboard with Ruby - ruby

I'm using Windows.
Is there a Ruby Way to make a dll call? I want to use the GetAsyncKeyState() function.

Haven't been a Windows user in a long time, but there's a Win32API library. Maybe this article helps:
http://www.rubytips.org/2008/05/13/accessing-windows-api-from-ruby-using-win32api-library/

You might want to look at the WIN32OLE library, or the DL library. They are designed for DLL access and Windows programing in Ruby. (NOTE: Although the librarys work, dynamic C access from Ruby does not seem to be an easy task, so use them only for sparse calls to the API. A Win32 program will do better in C, C++, C#, or .NET)

You may want to give FFI a look. It provides a fairly seamless interface to native libraries.

Related

Programming Unity Games with Ruby

So I see that unity has the support for c#, JS and Boo.
I could learn one of these but I would like to make a 'compiler' or something similar that would let me write ruby code and either output JS code or make a layer that could be read by the Unity compiler.
Is this even a possibility. Im willing to invest many hours in this and have a fair bit of experience.
If your question is actually "how do I compile Ruby to JavaScript" then that's easier to answer:
Opal: Ruby to JavaScript compiler
However, you're going to be mucher better off learning one of the supported languages. It's very hard to debug "your" code when what's running is a paraphrasing of the code in another language.
I'm not that familiar with C# but if it's anything like C, it's quite possible you could create bindings from Ruby to Unity and just use it directly. Likely you could even get some kind of community going. This would be much preferable to trying to auto-refactor languages.
I recommend the "play my code" site.
It is possible to "conpiles Ruby to JavaScript", to operate the Ruby Game in a browser, just as JS.
http://www.playmycode.com/build/edit/6172
Unity 3d doesn't use Javascript, i think unity corporation call it as javascript just for marketing purposes, Unity uses UnityScript which is Boo based implementation, you can see the source here https://github.com/bamboo/unityscript
So, even if you got some compilers ruby to javascript such as Opal, you'll still compile it to JavaScript and not UnityScript, there's a big diferences between them:
Javascript is a prototype based language, and UnityScript is an class based.
UnityScript is more JScript.NET than Javascript.
See more at http://wiki.unity3d.com/index.php?title=UnityScript_versus_JavaScript
I think the easily way to integrate ruby language rather to write a full compiler is integrate IronRuby, which is a Ruby implementation written in C#, which will generate bytecodes for CLR that Unity can read.
I did a similar project with python, which uses IronPython (https://github.com/cesardeazevedo/Unity3D-Python-Editor), it's still very limited, such you still have to call python code from C#, but it works and there's a interpreter that can help you in your development, if you want to create thousands of game objects with simple python commands.

Is possible to use QtConcurrent with Ruby (mingw-32)?

How can I use the QtConcurrent Qt module in Ruby?
I'm developing a small app that uses Qt (through the qtbindings binary gem) in Windows (Ruby 1.9.3 mingw-32) but I couldn't find a way to use threads (or use simple concurrent methods calls).
Any help and any example would be very helpful.
Thanks in advance.
I have a feeling that its no different than PyQt4, where QtConcurrent is not available because they can't easily wrap it. If its not being built with your Ruby bindings, its probably not available. You would need to stick to QThread and its siblings.

Ruby for the PIC32 Microcontroller

Is there an existing library to write code for the PIC32 in Ruby?
Currently I've been writing code in C to perform tasks on it, but I would love to use Ruby.
Thanks,
Andy
I doubt that there is an existing library for that task, but it should be possible (surely not without some effort) to extend Metasm to include a new assembler backend for your processor. It also includes a C parser/compiler.
EDIT: I just realized you are looking for a Ruby interpreter on that platform, which I hardly can believe exists.
I also doubt that Ruby on iron exists, but it would be nice to be wrong. :)
If your pic32 can handle an OS that would run Ruby, that might be an option. Otherwise you may be able to prototype a lot of your algorithms in locally run Ruby and then translate them to C on the PIC32.
Probably too late, but according to this link, mruby can run on pic32
As a consequence, the interpreter is now much reduced in size and can
be cross compiled for low cost 32-bit microcontrollers including ….
the PIC32 (MX7)! The official repository on GitHub contains already
examples for a few embedded platforms including the chipKIT MAX32!
https://github.com/mruby/mruby

Creating a minimalistic MSHTML-based window

I have a library for Haskell that can take an ordinary web application, run it on a local server, and then open up a window displaying that application using QtWebkit. The code to interface with Qt is very short. However, I would like to avoid the Qt overhead for Windows users.
It seems like the best approach would be to have an alternative to this QtWebkit-based C++ file that instead uses the MSHTML library on Windows. Unfortunately, I have almost no experience with Windows-specific libraries. It seems like I need to use the IWebBrowser2 interface, but that seems mostly speculative.
If someone can point me in the right direction on this, I would be much obliged. The final trick here is that it has to compile with MinGW. Not sure how much of a complication that is in this case.
Thanks
You can use hdirect to call the IWebBrowser2 interface from Haskell. It's messy to code against OLE/COM but it can do the job. Making a C binding to the interface is possible but if you need MinGW then it may actually be harder than a purely Haskell approach.

Programming language for GUI compilable to native binary

I need to write an app that reads a config file with info on the menu bars it needs to create.
Normally, I'd just use java, but I need the application to have the least run-time dependencies possible, this includes not forcing the user to download anything, even JRE, let alone something like NET Framework.
So I need something that can compile to an EXE (windows only for now), and that will allow me to CODE the GUI, so I can dynamically create it from my config.
BTW: something like C++ is a bit too low level, all I need is to create menus, and display HTMLs in a panel.
How about wxPython together with py2exe?
There is a nice tutorial on how to do it here.
If Java's too high-level and C++ too low-level, there ins't much in-between. Maybe Delphi?
I wouldn't totally write off using Java and/or Python for a few reasons.
1) py2exe can compile your Python code to an exe.
2) GCJ can compile your Java code to an exe.
Delphi is best chose for you. Because Delphi compile source code into native x86.
Unless you have serious reasons to avoid interpreted languages, I would suggest you better look into ways of packaging or compiling interpreted scripts because doing this will likely reduce your learning and development time.
I would write a simple GUI in Tcl/Tk, and then package it as a Starpack.
ActiveState provides a distribution (ActiveTCL) and a decent editor (Komodo Edit), and it is fairly easy to get simple GUIs going with Tk. Check out TkDocs for some hand holding.
Once you're done, you can package your code, a Tcl runtime, a database, and a virtual filesystem, all into a single executable that you can easily distribute.
Earwicker is right. You can use HTA:
http://www.interclasse.com/scripts/htanotepad.php
But if you know C++, then creating this type of an application is actually very easy with Visual C++. Use MFC, and statically link everything. You can draw the menu in the resource editor, and attach events to the menu items. I wouldn't use HTML if I were you. Just use regular Windows controls. But if you're really set on using HTML, you can embed a Browser control in the formview.
Have you considered D ? It has a syntax that is like a mixture of Java, C++ and Python with the ability to make native windows apps. The tutorials on dprogramming.com are great to get up and going with the language. For quick GUIs you'd be interested in The D Forms Library and the Entice Designer.
Here are some short video tutorials to get up and running with Entice.
Alternatively, have you tried Qt & Qt Creator? It takes a lot of the hair pulling out of C++ Programming and it's also cross-platform.
You say:
all I need is to create menus, and
display HTMLs in a panel.
A lot like a Web browser, then. If it's going to run on Windows, then the user has IE. Why not use IE to do all the work for you?
You can make something a lot like an .exe with IE, called an .hta:
http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx

Resources