Can GO be used as a scripting engine within an application? - windows

Can GO be used as a scripting language within an application ? I can't find any informations about this: is there a dynamic link library version which could be interfaced from a Windows application with some standard methods such as Compile(), Execute and features such as callbacks, variables sharing etc ?

This might sound strange at first but go with me on this: I think it would be a perfect candidate for a scripting language because it's compile time is so fast....hear me out...
Most scripting languages are interpreted, and so they do not require (or even provide in some cases) compilation. However compiled languages are safer in general because they can catch certain errors at compile time, which is better than, for example, catching a syntax error at runtime.
With Go, the compile time is so speedy that whatever program is running your Go code (e.g. a web server) could hypothetically compile the code on-demand if the code has changed, and otherwise use the compiled version.
Actually if you check out Google App Engine and download their dev web server for Go (https://developers.google.com/appengine/) you'll notice that their web server does exactly this. If you run through their Hello World tutorial for Go you'll notice that if you make changes to your code you won't need to recompile the Go code in order for the changes to take affect.

Go is not a scripting language. Because Go is designed for fast compilation, there have been some attempts to use it as a scripting language. For example,
gorun
GoNow

In theory (and perhaps somewhere out there w/o me knowing), Go can be used as a script language. Just note that it makes as much sense as using e.g. C as a scripting language.

No. Go code cannot be used within a non-Go application unless Go is responsible for starting up the whole app.

Related

Debug project written in multiple languages in VSCode

I am wondering how people typically go about debugging applications that are written in multiple languages.
For example, you could have some javascript that calls some back end python code. Is there a way to set up debugging so that you can start debugging in one language i.e. javascript, and then switch to the python debugger once that bit of code gets called?
My use case is with PowerShell and some .NET class libraries but it seems like there might be a broader set of use cases.

Adding/replacing/patching std libraries

I have a (self-written) runtime library which I have used in various programming projects over the years. It started life as a Pascal library in the early days of Turbo Pascal and has since progressed through incarnations in C, Perl and Lua. I am now contemplating to move this over to Go (not least because there are some interesting parallels between Go and Lua). A good part of Go's std library does more or less what my own libraries do (for instance, the flag package or the regex stuff) in which case I can either use them directly or get away with writing a small interface layer.
Problems start with those packages where my model is too different from Go's for a simple interface layer to hide the differences (a case in point are the directory-walking functions). I see two ways forward: re-implement my code as a Go package; or patch some of the existing Go runtime packages.
I am leaning towards the first option, not least because this will help me to get to grips with the language. Then again, I've often patched source code for my own requirements and I am comfortable with that approach. The changes would be localised and it shouldn't be too difficult to merge future version of Go's runtime library with my changes.
So is it feasible, advisable to do that or do I have to regard the Go sources as read only?
So is it feasible ... ?
No. Everything will break once you touch the Go stdlib as every package out there relies on the stdlib.
So is it ... advisable to do that ...?
No, not at all.
[D]o I have to regard the Go sources as read only?
Yes.
Note that what you call "runtime" is not the Go runtime but the Go's standard library.

why use Google V8

I don't get it. I'm a C/C++ programmer, what's the possible use of V8 for me? There are few examples and tutorials out there, and they all lack substance - I don't want to use another library to just add a couple of numbers or print something in a console window.
My question is: is there a real use for this technology, and if yes, then would be the scenario?
Also, can I do any part of GUI this way?
Help is appreciated.
"V8 is Google's open source JavaScript engine"
So the whole point is ability to write code in JavaScript, and run it quite fast (for an interpreted dynamic language). Google Chrome, which is written in C++, uses it for internal scripting — not only for regular web page scripting, but also for extension code. Let's consider this as a 'real use'.
So, if your app needs scripting, V8 may be good for you (JS is not a perfect language, but stil quite decent). As for GUI, you'll need to bind your GUI components with JS first, there's no built-in UI components (as Tk in TCL).
One real use of v8 is node.js. I hope that is good enough
Google V8 is a JavaScript engine.
I don't really think it is what you are looking for.
V8 is a JavaScript engine. The most common use for it is to allow users of your software to write scripts in simpler language than that your software was written with (C++ in your case).
It´s the same approach of Matlab, AutoCad, Microsoft Office, and etc.
If you write any kind of commercial application, you can expose some APIs and allow other developer to create addons for your applications without require them to know C/C++.
How about this for real use: You can use javascript as a debugging or testing tool - add a javascript console to your app and bind the commands of your GUI application to javascript functions, and you'll be able to test your UI application using javascript scripts. This way you'll reduce the amount of manual testing needed - manual testing would only have to verify that a correct command was excutes as a result of user action.
You can do GUI in javascript the same way that Qt is being used in Python and other scripting languages (see PyQt, and QtRuby, PerlQt, etc.). For how to create bindings for V8 you may want to check out this

Creating GUI desktop applications that call into either OCaml or Haskell -- Is it a fool's errand?

In both Haskell and OCaml, it's possible to call into the language from C programs. How feasible would it be to create Native applications for either Windows, Mac, or Linux which made extensive use of this technique?
(I know that there are GUI libraries like wxHaskell, but suppose one wanted to just have a portion of your application logic in the foreign language.)
Or is this a terrible idea?
Well, the main risk is that while facilities exist, they're not well tested -- not a lot of apps do this. You shouldn't have much trouble calling Haskell from C, looks pretty easy:
http://www.haskell.org/haskellwiki/Calling_Haskell_from_C
I'd say if there is some compelling reason to use C for the front end (e.g. you have a legacy app) and you really need a Haskell library, or want to use Haskell for some other reason, then, yes, go for it. The main risk is just that not a lot of people do this, so less documentation and examples than for calling the other way.
You can embed OCaml in C as well (see the manual), although this is not as commonly done as extending OCaml with C.
I believe that the best approach, even if both GUI and logic are written in the same language, is to run two processes which communicates via a human-readable, text-based protocol (a DSL of some sort). This architecture applies to your case as well.
Advantages are obvious: GUI is detachable and replaceable, automated tests are easier, logging and debugging are much easier.
I make extensive use of this by compiling haskell shared libs that are called outside Haskell.
usually the tasks involved would be to
create the proper foreign export declarations
create Storable instances for any datatypes you need to marshal
create the C structures (or structures in the language you're using) to read this information
since I don't want to manually initialize the haskell RTS, i add initiallisation/termination code to the lib itself. (dllmain in windows __attribute__ ((constructor)) on unix)
since I no longer need any of them, I create a .def file to hide all the closure and rts functions from being in the export table (windows)
use GHC to compile everything together
These tasks are rather robotic and structured, to a point you could write something to automate them. Infact what I use myself to do this is a tool I created which does dependency tracing on functions you marked to be exported, and it'll wrap them up and compile the shared lib for you along with giving you the declarations in C/C++.
(unfortunately, this tool is not yet on hackage, because there is something I still need to fix and test alot more before I'm comfortable doing so)
Tool is available here http://hackage.haskell.org/package/Hs2lib-0.4.8
Or is this a terrible idea?
It's not a terrible idea at all. But as Don Stewart notes, it's probably a less-trodden path. You could certainly launch your program as Haskell or OCaml, then have it do a foreign-function call right out of the starting gate—and I recommend you structure your code that way—but it doesn't change the fact that many more people call from Haskell into C than from C into Haskell. Likewise for OCaml.

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