Slashdot Mirror


Lightweight Scripting/Extension Languages?

Andy Tai asks: "Extension languages are designed to be embedded in applications to support customization of the application behavior. Common scripting languages, like Perl and Python, are fairly 'large' with powerful run-time engines and libraries and are widely available and 'script' writers usually assume their stand-alone existences in the deployment environment. However, if one is looking for a language that's small enough so its source can be embedded in the distribution of and built as part of the application, Python and Perl may be 'overweight.' For the real lightweight choices there are Lua and Tinyscheme. Are there others? What are people's preferences and opinions regarding lightweight extension languages?"

26 of 176 comments (clear)

  1. Guile by crmartin · · Score: 3, Informative

    God knows the words "lightweight" and "Gnu" don't generally go together, but how about Guile?

  2. TinyTCL by the_womble · · Score: 3, Informative
    what about Tiny TCL

    Its easy to learn and use (very good if the people using our embeded language are not programmers). Its mature, supposed to be extensible, and if you decide you need something more powerful later on even the current full verion is not that bloated.

    1. Re:TinyTCL by Twylite · · Score: 4, Informative

      Tcl/Tk proper is not a bad idea either. If one does not need the GUI part (Tk) then Tcl is relatively easy to integrate into a project, and is under 200k.

      HowToEmbed from the Tcl Wiki is a good starting point, and MkTclApp may help.

      Tcl has very consistent and simple syntax (although it can get rather confusing at times), and it is very simple to add new command into your application that are exposed via Tcl. One of the nicest aspects of Tcl is that is it seriously multi-platform.

      Of course this all depends on the requirements: how powerful does the language need to be, what functions must it provide, what types do you need it to be able to handle, how small is "lightweight", etc.

      --
      i-name =twylite [http://public.xdi.org/=twylite], see idcommons.net
    2. Re:TinyTCL by ianezz · · Score: 4, Informative
      One of the nicest aspects of Tcl is that is it seriously multi-platform.

      Another nice aspect of Tcl is that it can easily evaluate code in a different stack frame (example: in the caller's context), and source code can be easily passed to procedures as strings between braces (as it is usually done), so extending/reimplementing the language control structures is as simple as writing a new procedure (and no special/ugly syntax is required).

      That's as close to Lisp macros as you can get.

  3. How much do you need? by Ripsnorter · · Score: 2, Informative

    Just how much customising do you need?

    From my experiance if you only need a little customisation then you can do most of that stuff from a config file, .ini if you want it to be easy to edit, xml if your going to write a gui to do it or your users are compertant. Any more than that your better off going with something like python or perl, they are widely known, and have rich libraries to let the people using the app do some really imaginative things.

    The other thing that you can do is write your app in such a way that it is easy for scripting langs to get there hooks into. For example, on windows you can do this by providing com interfaces to all the things you want to have control over, then you can use any lang you want to control your app.

  4. paxscript by glob · · Score: 2, Informative

    i recommend you look at paxscript.

    it's the most complete and quickest of any embedded source stuff that we've investigated.

    supports basic, c, objectpascal (ie delphi) and javascript.

    not free, but you get the source when you purchase it (US$179).

    delphi and borland c++ builder only.

    --
    nostrils
  5. REBOL by the_greywolf · · Score: 3, Informative

    didn't see anyone else mention it, so i thought i would.

    REBOL is a ridiculously simple and easy-to-learn web-oriented language. so easy, in fact, that i wrote a fully-functional IRC dice bot in under 400 lines, overnight. and if that weren't impressive, then might i add that i was running on ZERO caffeine, learning the language for the first time, learning IRC Client protocol for the first time, and came up with a few unusually witty statements and insults to boot?

    now the bad part: REBOL is not open source. poo. (i really was a bit disappointed.) but REBOL/Core is free (for any use, i gather), and the license fees for View and Command seem rather reasonable.

    the nice part: it has been ported to and runs on about 43 platforms, last i checked, and is light enough that the executable weighs in at around 250kb for the win32 release. (haven't used the other platforms, so no comment.)

    it runs on just about every unix i've heard of, on every relatively common configuration, and works beautifully and seamlessly. and, after a quick glance, i see it runs on serveral major embedded systems, including WinCE, QNX, and Linux, and will even run on my friend's dated Amiga.

    enjoy and happy coding. :)
    --
    grey wolf
    LET FORTRAN DIE!
    1. Re:REBOL by swdunlop · · Score: 3, Informative

      I had a very guilty love for REBOL, but it hasn't changed much in the last three years.. Many of the warts on REBOL/View are still there, and it's still not fully documented. They also haven't finished their port to OS X, so it isn't as perfectly cross platform as I would like..

      And.. Finally.. How does one embed REBOL in an open source application?

  6. Developing for windows? by KILNA · · Score: 4, Informative
    --
    Error: PANTS NOT FOUND. Press <F1> to continue.
  7. Object Forth? by samjam · · Score: 4, Informative

    ficl.sourceforge.net

    A portable object oriented forth at less than 100K for a full implementation, able to handle calls from your apps as well as call your apps fgunctions or other dll's.

    Under a BSD-ish license.

    The upside:
    1) Its tiny
    2) The forth code you write will be tinier

    Downsides:
    1) You need to learn forth (I mean properly) to appreciate it.

    Forth is unlike most other languages, it was designed to avoid the debug, recompile cycle that is so common.

    Sam

  8. Re:Anything but odd/new language... by Anonymous Coward · · Score: 2, Informative

    Assuming you already know at least one other language, learning LUA takes exactly 1 hour. That's it. Spend an hour on it, and you are a master LUA programmer. That's a big part of its appeal.

  9. How about JavaScript? by Rich · · Score: 5, Informative

    I've been working on a system for embedding JS in KDE apps (amongst other reasons it is a about 1/10 the size of a python interpreter). You can find lots of information at http://xmelegance.org/kjsembed. The interpreter in KDE has no dependency on KDE/Qt or anything else so you might find it usable in your app.

  10. Copy of an advogato article by DavidNWelton · · Score: 3, Informative

    I guess atai must have submitted the same question here as well, but the "original" discussion took place on advogato:

    http://www.advogato.org/article/735.html

    It would be useful if he could state what his requirements and limits are, in detail, because that's a very necessary part of evaluating what would work.

  11. Re:Javascript! by Anonymous Coward · · Score: 5, Informative
    Mozilla implementation of JavaScript in C is available at http://www.mozilla.org/js/ and pure Java implementation is at http://www.mozilla.org/rhino/

    And btw, ECMAScript/JavaScript can be pure functional as well.

  12. EiC? by Futurepower(R) · · Score: 2, Informative

    Or, how about EiC, now hosted at Sourceforge. "EiC is pointer safe."

  13. Consider Ruby by urbangipsy · · Score: 3, Informative

    What about Ruby (ruby-lang.org). It's easy to learn, powerful and has a reasonable set of classes and methods built-in. It's also quiet widespread nowadays, lightweight compared to Python and easy to embed via libruby.so
    see the Ruby book (section Embedding a Ruby Interpreter

  14. Re:Anything but odd/new language... by JohnFluxx · · Score: 2, Informative

    I think you misunderstand.
    say I have a program, written in C, and I want to add full python scripting support.

    One way would be to try to add in the python interpreter into the program, and this is the way you immediately think of.

    The second way would be to have a small python program that calls your program (so all you rewrite in python is your main() function and the function that does event handling.)

    The link I provided gives reasons on why they consider the second way better.

  15. Nasal, a javascript-like language by truth_revealed · · Score: 2, Informative

    Nasal is a very well designed small embeddable language with a Javascript-like syntax and an LGPL license. I prefer it to Lua because I am not fond of Lua's Pascal-style syntax. Be aware that Nasal is not very battle-hardened yet and does not have even a 1/100th of the developer community of Lua.

  16. LUA by schapman · · Score: 2, Informative

    lua is a great scripting language when it's used well. When i was studying game development in school, we were introduced to it as a good way to drive out games. Its easy to add functionality for it... its fast... it simple. I could write all my rendering/sound/network/input code in c++, and just have interfaces for everything from lua... this way, when i wanted to drive a game app, i could do the following: (pseudo lua... hmm... pseudo scripting :) ) load level load char at xyz load enemy at xyz go then, my c++ code could handle all the collision detection/AI/proper sounds for things... it all comes down to good design. Something like lua is great for having somethign high level drive a low level engine.

    --
    Wouldnt you like to be a pepper too?
  17. Nasal by Nevyn · · Score: 2, Informative

    When I was answering this question, I ended up looking at nasal. While not perfect, it was the closest to what I wanted ... and was under a compatible license (LGPL). But then I wanted something small, lua is way too big.

    --
    ustr: Managed string API with ave. 44% overhead over strdup(), for 0-20B
  18. Re:The need for "extension languages" by Webmonger · · Score: 2, Informative

    If you accept the notions that
    1. scripting languages speed development
    2. high-level code does not need to be optimized

    Then for an app like Neverwinter Nights, it would make sense to use a scripting language for the high-level code (e.g. menu handling code), while leaving the performance-critical code (e.g. 3-D rendering) in C, C++ or assembler.

    Coded like this, NN might not crash as frequently because either
    - The crashy code would be implemented in a scripting language, and so memory handling would not be a problem

    - The crashy code would still be in C/C++, but since the other code had been written more quickly, there would be more time to fix it.

    The current issue of the C/C++ Users Journal is all about mixed-language development.

  19. Re:The need for "extension languages" by be-fan · · Score: 2, Informative

    I'm not talking about Python. Python is positioned as a scripting language, and hence doesn't have a powerful compilation infrastructure. Although, Pysco does some very cool dynamic optimizations for Python.

    In contrast, there are many high-level languages like Common Lisp, Dylan, Scheme, ML, Ocaml, etc, that have very powerful native compilers. They do optimizations that C/C++ compilers simply cannot do, because of the low-level C memory model. Literally decades of research has gone into making these compilers, and they have optimizations that (while not quite magical) are very impressive.

    Variously:

    - There are type-inference optimizations that eliminate the overhead of dynamic dispatch.
    - There are heap-analysis optimizations that stack-allocate objects whenever possible, to avoid heap allocation.
    - There are analysis that avoid heap-allocating closures.
    - There are analysis that eliminate type checking and array bounds checking.
    - There are analysis that perform large-scale optimization of class heirarchies, to eliminate the over head of OOP.
    - There are memory allocation analysis that reduce the overhead of garbage collection (region inference).
    - They do method specialization, allowing the C++ template advantage of generic functions optimized for a given type, without actually having to deal with explicit type parameters.

    Some useful pointers:

    Apple Dylan Wiki
    Lisp vs Java vs C/C++ performane
    Bigloo Scheme Compiler
    Gwydion Dylan compiler
    CMU Common Lisp Compiler
    UW Vortex Compiler
    MLKit ML Compiler
    Ocaml Compiler

    --
    A deep unwavering belief is a sure sign you're missing something...
  20. Re:The need for "extension languages" by Anonymous Coward · · Score: 1, Informative

    The main reason why applications are developed in C is cross platform compatibility. That said, scripting languages are getting better about being everywhere--but they can never be everywhere where you might need a truly portable application (embedded platforms and wacky operating systems come to mind).

    I agree that writing your basic GUI applet in C is probably counterproductive; scripting languages can certainly be much more portable than C, as they hide a lot of the messy machine internals. However, for core infrastructure like server daemons, core utilities like grep, and other system-level programming tasks should be done in a portable language like C, a compiler for which is one of the first tasks facing the designer of a new architecture (after the core operating system and a few basic libraries). Interpreters like Python and the rest, after all, are written in C.

    Also, C is the de facto language for library bindings and all the rest--you can be pretty much guarantee being able to link a library into any other language if it exposes a C API. The same wouldn't be true for a Python or Perl module, C++ library, or Java class file.

    Finally, C gives you much more control than higher-level languages. That can be both a blessing and a curse, but at least it means you don't need to hack the C compiler to get a feature that you want. In many corner cases, you'll need an extra C function or two to implement lower level functionality. One of the strengths of Python (the main strength, in my POV) is that it makes it easy to script C-based programs and libraries.

  21. COM interfaces and stuff like it by Latent+Heat · · Score: 2, Informative
    Multi-language capability gets slammed with the argument that 5 different programming teams within an organization are going to write in 7 different languages, and how do you maintain that mess. To me, multi-language means I write the app in whatever language suits me, and users of my app write scripts and extensions in whatever language suits them.

    COM/ActiveX works swimmingly in this regard in that you have a choice of languages for both producing and consuming COM/ActiveX components, and COM allows you to pass object references across the barrier while ActiveX allows you to work with GUI widgets in this way. And it is true multi-language, not the fake multi-language of the .NET languages.

    On the other hand, COM/ActiveX pretty much limits you to Windows, you have to be careful of the lowest-common-denominator effect of which COM data types work in which languages (the more restrictive set of "Automation" types compared to the wider set of C-compatible types and a more restrictive situation for scripting languages and Web browsers than with Visual Basic 6). Also, COM/ActiveX can get ugly in some environments (C++ and MFC/ATL -- you are really stuck taking the Wizard-generated code at face value unless you really know what you are doing), and as a component developer you have to pick up some IDL basics.

    Is there anything out there that even comes close? With the Python/C-C++ meld, you are pretty much restricted to Python on one end and C++ on the other hand, and the C++ end is, shall we say, a bit lower level than the Python end, although there are things like SWIG that look amazingly like, hey, IDL and Visual Studio Wizard code.

    Another thing I have looked into is the Matlab-Java meld -- a lot of academic engineer and scientists use Matlab as their all-purpose scripting tool, but I wouldn't want to develop high power apps in it. The Matlab-Java meld is surprisingly clean, the Java side can be a Swing app and it runs in its own Swing windows. Again, you are restricted to Matlab on the scripting side, Java on the custom app side, but the interesting thing is that it is pointedly the sort of thing SUN isn't interested in. According to the SUN world view, Java is everything you would ever need and the idea of scripting Java from anything else doesn't enter into their universe.

    Is there anything else out there that scripts Java? I suppose there is Jython. Anything else?

  22. Re:Anything but odd/new language... by JudasBlue · · Score: 2, Informative

    "It's a good rant but it's not really very relevent - writing your app in python (at least in the way he describes) simply isn't plausible if you're writing an app for commercial or even mass distribution - you can't rely on an existing Python installation and if you've got to package one with your installer then theres hardly any more work to embed an interperter instead."

    This is old enough it will probably never be read, but that isn't true. There are utilites that do this in a snap, in addition to finding any extension package or dll deps that your python is using automagically in almost all cases. Just today I took a small app written in python using WxWindows ran it through py2exe and it runs on all flavors of windows, without python or wxWindows libs installed on either one. Took me about ten minutes.

    McMillian Installer will do the same trick, tho I haven't used it recently. Mcmillan also does the same thing for Linux, where I wish a lot more people were making packages available as no dep binaries as well as more traditional source packages, but that is just me.

    Now, as for your other points, if you happen to want to write your code in Python, well, that is a different matter. But if you choose to, it is very easy and fast to distibute your program binary without deps.

    --

    7. What we cannot speak about we must pass over in silence.

  23. Check out Ferite by FireChipmunk · · Score: 4, Informative

    Ferite is a scripting language and engine all in one managable chunk. It is designed to be easily extended in terms of API, and to be used within other applications making them more configurable and useful to the end user. It has a syntax similiar to a number of other langauges but remains clean and it's own language.

    I love that it was designed from the Start to be Thread Safe and Embeded, unlike PHP or Python.