Scripting language/Compile Qt DLL from Metadata?



  • Be patient because this question requires a little background to answer appropriately

    I am writing a large application that will make use of scripting for specific functionality. The script language that comes with Qt is too sophisticated for some of the target demographic that this application is meant for. The script language I am looking to use would need to be simple, easily read and learned, and void of the requirement of special characters in variable names or things like braces in function definitions. I have done a lot of research and have not found a good language that is still maintained on a regular basis (one older language called Falcon may have sufficed... but it is no longer useful as it has fallen into disrepair without updates.)

    Basically I want to be able to call Qt functions using a simple syntax. Theoretically I could do this making use of Qt's equivalent of .NET reflection class using metadata and the moc system. However, I would like to improve upon this if possible (for the sake of performance) by either using a virtual machine, or by somehow being able to compile executable code from script fragments (which will be a common phenomena in this application). What would really be fantastic is to be able compile a DLL from the script based on Qt Metadata... is this even remotely possible?



  • Anything is possible if you are willing to devote the time and effort. Developing a Domain Specific Languages (DSL) is a common technique for providing a simplified interface to your application. Scripting languages like Javascript are often extended with application-specific functionality and data for this purpose, as Qt does. If Javascript is too complex you might consider VBScript. VBScript is more verbose, but uses less special characters and such. Since this appears to be your first attempt atcreating a DSL I suggest you stick with implementing a well-defined language like VBScript rather than attempting to create your own (unless it is very simple). If you can, take a course on compiler theory - that will give you many of the tools you need for this kind of work.

    It is possible to develop a compiler that produces binary dlls and such on the fly that you can dynamically load, but I would highly advise you avoid this for the time being. I think you will find the challenge of developing a parser and interpreter for your chosen scripting language to be more than enough of a challenge your first time through. Again - I highly advise you take a course on Compiler Theory if you are serious about this. If you can't take a course, then you can get a book like this: https://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/0321486811/ref=sr_1_1?ie=UTF8&qid=1488277925&sr=8-1&keywords=compiler+theory



  • Would python be an option? you can easily use PyQt to integrate with Qt


  • Qt Champions 2016

    Hi
    Besides calling Qt function, what other language constructs do you need?
    if/then/else
    variables
    array
    etc ?

    +1 for python as there is no { } as u ask about



  • @VRonin Python Syntax is appropriate. However, I do not like Python because of its lazy (IMO) lack of basic programming features (unless it has been updated recently to include them). It is terribly inefficient as a result. A classic example is the Python for loop which wastes both time and memory. Technically, they do not exist as Python essentially turns for loops into a "foreach" loop. Creating a collection of integer objects to run a basic counter is insane in my book.

    Visual Basic is good too though a bit messy when it comes to OOP. An ojbect oriented version of BASIC that is not Microsoft specific would be a nice candidate. Unfortunately I am not sure that one exists.

    @mrjj said in Scripting language/Compile Qt DLL from Metadata?:

    Hi
    Besides calling Qt function, what other language constructs do you need?
    +1 for python as there is no { } as u ask about

    Pretty much the things you mentioned plus objects. I need variables to be able to hold an object and perform operations on them. The point is to write scripts to perform the manipulation of objects to be presented. Kind of like Flash's ActionScript.

    EDIT: Plus the ability to define functions. The perfect example of the kind of language (syntax wise) is Papyrus Script that is used by Bethesda games. Very, very easy to learn and read even if the modding tools are a pain to use because they don't always work properly.


  • Lifetime Qt Champion

    Hi,

    If you would like to provide your own DSL, then LLVM might be worth considering.

    Here is a presentation about implementing a small DSL with LLVM.

    Hope it helps


  • Qt Champions 2016

    @primem0ver
    Hi
    Well, most ECMAScript based/inspired script language
    Well , what about lua then ?
    https://www.lua.org/

    Or this is also pretty cool
    http://www.angelcode.com/angelscript/
    But most likely too advanced and c++ like in syntax.

    There is also the good old ( @SGaist , valid point! , its deprecated but very solid )
    http://doc.qt.io/qt-5/qtscript-index.html
    Which can "cache it"
    http://doc.qt.io/qt-5/qscriptprogram.html#details

    I would go with JavaScript as its very easy to integrate and for simple stuff, its pretty basic.
    However it does have {} for functions and single threaded.


  • Lifetime Qt Champion

    I'd avoid QtScript since it has been officially deprecated and removed from the official binary package. You can still built it by hand though but it's not necessarily a good idea for a new project.



  • @mrjj
    Java/ECMAScript is too full of "unnecessary" symbols that I refer to in my OP. Personally... I love the C style syntax and if it weren't for the more varied nature of my target population I would be perfectly fine with embedding Qt's version of ECMAScript; however I also recognize that people with a non-programming background may take one look at a file full of braces and other symbols they are not used too and say "I can't learn that!" This is what I am trying to avoid.

    LUA is a nice language from a syntax perspective but it does not handle object oriented programming well because its only true object type is the "table". I really have no patience for dealing with its convoluted table structures.

    @everyone
    The problem is that I cannot find a script language that suites my needs. Like I said above... I have research this extensively over a period of time. This is the reason for my OP (original post).

    Recently I have found a need in another project to create a very simplistic script like "language" for a solution in a .NET program. System.Reflection in .NET makes this pretty easy to do. I could do the same thing I did for this recent project in Qt because of the metadata used by Qt's object system. This gave me the idea of "what if I could somehow use the metadata to make it easier to do linking?" and post my original question. My current on the fly "translation" of the recent script I created does not solve the issue of the need for efficiency in my larger Qt project that could be resolved by either a VM or even better... the ability to compile a DLL based on linking to functions using Qt metadata (which was my original curiosity).

    One things that may help you understand the nature of what I am trying to do: Cold Fusion is an ideal language as it uses a VM, it has a basic syntax, AND it is natively embedded into xml (which is where many of the script fragments will be placed). It would be fairly simple to write a "translation" utility that turns script text into Cold Fusion XML directives. Unfortunately it is a proprietary Adobe product. In my experience Adobe products cost way more than they are worth; especially considering the decline of Flash after they bought it from Macromedia and that Flash is their only other script technology.

    @SGaist : I have looked into LLVM and scripting languages that use it. Unfortunately, I have already looked into the big lanaguages which already exist on this platform. I am afraid that they don't really suite what I am trying to do very well. I appreciate the link though as it seems to contain some information I was looking for about creating my own language using that particular platform.



  • @primem0ver - have you considered providing your users with a visual workflow editor? For non-programmers, a visual workflow maybe easier to work with. Various products provide such an interface for their less technical users, while also providing a more fully featured programming/scripting language like java script for the more advanced users. Unreal Engine provides Blueprints for users who want to avoid c++ programming: https://docs.unrealengine.com/latest/INT/Engine/Blueprints/

    Microsft provides a Workflow Foundation for Windows .NET Applications that I've used before. I've also worked on in-house workflow engines before. You can make them as fully featured or as simplified as you want. The Windows Workflow Foundation basically provides a visual programming language - you can do basically anything and everything that you could do with C#. The in-house one I worked on provided a script activity for advanced functionality, but the rest of the visual blocks provided high-level activities like send an email to a manager for approving a Purchase Request. Or: run a report and email it to me when it completes. Or: update a record in the database. No curly braces required!



  • @iam1me
    Thanks for that suggestion. It is a really good one which I may implement. However...

    @everyone
    I think I just thought of a way I may be able to do exactly what I wanted to do when I posted this question. Tell me what you all think. I believe I actually can convert my own script language to a compiled Qt DLL by "cheating." The idea is that I use a parser to convert my symbolic script code into C++ code and then compile the C++ code into a DLL using Qt's command line compiler. If I were to decide on a strongly typed syntax, I could use am1me's suggestion for helping non-programmers not have to worry about types while the programmers should be fine with using types.


  • Lifetime Qt Champion

    Just one thing: Qt doesn't have any compiler, it's "just" a framework. It will be whatever your platform provides.



  • Huh? Then how does the Qt Creator work? IT compiles stuff doesn't it? Personally I use the plugin for Visual Studio but the documentation says you can compile stuff from Qt Creator.


  • Qt Champions 2016

    @primem0ver
    Creator is an IDE
    You can make it work with most compilers.
    It calls external tool for compiling.
    The compiler is not part of Qt.
    ( except the mingw on windows. there the compiler is included in the installer)

    So no, there is no Qt c++ compiler. It will be Visual Studio or mingw or Xcode or gcc or what ever a platform offers. :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.