Juce & Lua


#1

There’s been a few mentions of using Lua, but I’m not sure anyone has specifically said that they’ve used juce and lua. My questions would be:

How hard was it to hook them together - particularly the way lua needs thread and mutex primitives. Will juce easily yield the right hooks in a cross-platform way?

And how easy was it to expose your classes? I’m looking to embed, not to access juce components in a global way: I’d define each class or object I need, and can provide getters and setters for properties.

Thanks,

Bruce


#2

I’m using LUA as a scripting language to extend my application, in the manner of JavaScript in a web-browser, not as a development language in its own right.

From your post, I’m guessing you’re looking to just use JUCE as a toolkit for LUA, right? If so, I can’t give much input as I’ve not really tried that.

From my perspective though, LUA is very easy to couple to C++. I built a lightweight wrapper around JUCE’s XmlElement class to provide basic XML support to my scripts, and it was extremely easy to do, and the resultant LUA code is very readable.

I can’t speak for any of the auto-wrap tools, as I’m actually trying to limit the functionality of LUA within my app at least until I can build in safe guards[1].

[1] While I doubt any of my co-workers, or our summer students, would deliberately write malicious code, I know if I leave loopholes in, I’ll forget about them, and if other departments start using my app, that could present problems in the future.


#3

That’s exactly what I’m looking to do - scripting to extend what an app will do. Funnily enough, most of my data is in an XmlElement bonded class (extends it with locks, versioning and some added abilities).

Thanks for the info. Anyone else? It sounds like the way to go, but I’m sure there’s some gotchas.

Bruce


#4

Is Lua absolutely required ?

Because there’s a python wrapper for Juce lost somewhere on the forum…
I’m sure more people knows python than lua.

Also Kraken as made an (excellent) scripting engine with Angelscript, you should probably contact him. (please have a look to http://www.anticore.org/juce )

You can also look into javascript, with a “DIY” with CliPP ( http://clipp.sf.net ), which is easy to link thanks to C++ templates.

Hope it helps, I’ll have to look into this too, soon.


#5

[quote=“X-Ryl669”]Is Lua absolutely required ?

Because there’s a python wrapper for Juce lost somewhere on the forum…
I’m sure more people knows python than lua.[/quote]

I chose LUA over Python for two reasons: firstly I couldn’t find a way, and I’m not sure it’s possible, to statically link the entire Python runtime into my app. With LUA my app size grew by only 280K when I added scripting, and the program is still a standalone exe. Secondly, I found that it was much easier to remove functionality from the language with LUA. If I want to block scripts frm having file access, it’s trivial to do in LUA.

The trade off is that Python is a feature rich, and complete language, where LUA often requires that you roll your own libraries as the base language is pretty stripped back.

I haven’t looked that closely at AngelScript. I vaguely recall deciding I preferred LUA’s syntax, but it’s certainly worth checking out.


#6

Well in the specific case of XML, garbage collection is pain. You’ll need to do your own reference counting as nodes can easily go out of scope unexpectedly. If you aren’t careful you’ll find the node that you are working woth suddenly vanishes because it’s parent just got deleted.

In most cases you wont need to worry about garbage collection, it’s pretty easy to do, but in the case of owned components, espeically for tree-like structures, your wrappers will need some heavy custom behaviour.

That said, the LUA code is nice and readable:


wibbleXML = xml.new("wibble")
blahXML = wibbleXML:addChildElement("blah")
myTextXML = wibbleXML:addChildElement("sometext"):addText("some text")
wibbleWriteToFile("c:\\wibble.xml")

#7

Thanks for the Clipp link. I wanted to use Javascript, as there’s so many ways to learn it. Python seems awkward to me - I don’t really want to deal with, and Angelscript doesn’t seem mature and documented enough for an end user.

I dabbled with SpiderMonkey, but the complexity and dependancies ticked me off.

Lua still looks good, but js would be better, as long as Clip supports multi-threading, it seems to have everything else I need.

Bruce


#8

[quote=“Bruce Wheaton”]Thanks for the Clipp link. I wanted to use Javascript, as there’s so many ways to learn it. Python seems awkward to me - I don’t really want to deal with, and Angelscript doesn’t seem mature and documented enough for an end user.

I dabbled with SpiderMonkey, but the complexity and dependancies ticked me off.

Lua still looks good, but js would be better, as long as Clip supports multi-threading, it seems to have everything else I need.

Bruce[/quote]

hi Bruce

I’m new to Juce - how was your experience in using JS with Juce?
Can you give us some insight in a basic JS + Juce hello world?

Thanks !
Bert


#9

I didn’t ever use Juce with Javascript. I dabbled with SpiderMonkey, but it has a heavy dependance on NSPR is you want to use it multi-threaded, and that’s a pain.

Lua seems easier. I have it compiled in, which was a cruise, but have yet to really exercise it.

SpiderMonkey may have improved, since Macromedia donated their flash engine. But I hate ActionScript, so oh well.

Bruce


#10

[quote=“Bruce Wheaton”]I didn’t ever use Juce with Javascript. I dabbled with SpiderMonkey, but it has a heavy dependance on NSPR is you want to use it multi-threaded, and that’s a pain.

Lua seems easier. I have it compiled in, which was a cruise, but have yet to really exercise it.

SpiderMonkey may have improved, since Macromedia donated their flash engine. But I hate ActionScript, so oh well.

Bruce[/quote]

thanks for replying.

I just wonder if there is a way to put together a juce GUI by mostly scripting and just get down to the C/C++ level when really necessary, for threading stuff or for hardware I/O, etc.

I still think somehow that writing C++ slows development down significantly compared to using a script lang. Maybe I’m wrong…


#11

You’re probably right, but juce is the quickest I’ve found. It makes a lot of sense, and it’s predictable.

Look at PyJuce - it should do what you want with python. Or AngelScript, I think.

Bruce


#12

[quote=“Bruce Wheaton”]You’re probably right, but juce is the quickest I’ve found. It makes a lot of sense, and it’s predictable.

Look at PyJuce - it should do what you want with python. Or AngelScript, I think.

Bruce[/quote]

is PyJuce maintained at all or is it a one time project sort of thing?


#13

FWIW, I’m looking at Lua at the moment within my Juce apps, to give my users a way to add some very specific user-scriptable features; so they can make the app behave in specific, custom ways in certain circumstances.

Looks promising so far - take a look at the “Programming in Lua” book (very clearly written); also “Game Development with Lua”.

One additional reason for my interest in Lua, is that it is very useable in the context of scriptable or extendable games/apps for mobile devices which are not necessarily Juce-based (as Lua is very small and quite fast).

I really like Python, but Lua is also a very nice, clean language and is quite easy to sandbox; it is also not fussy about indentation (saving confusion of script novices who might be extending my products with simple bits of script!).

Hoping this is of interest!

Pete


#14