Is Lua right for me?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Is Lua right for me?

Chris Losinger
	Hi,

	I'm looking for a scripting language to embed in an interactive
image manipulation package. I've looked at the Lua FAQ, the intro pages and
scanned a few months worth of this list. But, i think i need to ask the
list, to get the answers i need...

	The language i use needs to be:

	a) usable for people who aren't programmers (think engineering
students). Lua looks like it might be ok here.

	b) fast enough to do simple arithmetic on enourmous data sets (2d
image manipulation). it doesn't have to be real-time, but it shouldn't be in
elephant time either. any opinions?

	c) limitable. i need to be able to limit the language to keep users
from going outside the scope of the host application. can this be done with
Lua?

	d) usable with huge data sets. i read a few messages about Lua's
garbage collection system and images that give me doubts.. i want to create
"image" objects that allocate data with Win32's GlobalAlloc function, and i
need this memory to be released when the object goes out of scope. is Lua's
GC going to complicate this?

	i'd appreciate any info i can get...

	-c

Reply | Threaded
Open this post in threaded view
|

Re: Is Lua right for me?

Brian Mitchell-2

On Wed, 3 Jan 2001, Chris Losinger wrote:

> 	The language i use needs to be:
> 
> 	a) usable for people who aren't programmers (think engineering
> students). Lua looks like it might be ok here.

Yes, I think lua would be fine here.

> 
> 	b) fast enough to do simple arithmetic on enourmous data sets (2d
> image manipulation). it doesn't have to be real-time, but it shouldn't be in
> elephant time either. any opinions?

Some high level algorithm primitives can be in C, increasing speed.

> 
> 	c) limitable. i need to be able to limit the language to keep users
> from going outside the scope of the host application. can this be done with
> Lua?

Yes. In Lua4, all the standard libraries are optional. You have to
specifically enable them.

> 
> 	d) usable with huge data sets. i read a few messages about Lua's
> garbage collection system and images that give me doubts.. i want to create
> "image" objects that allocate data with Win32's GlobalAlloc function, and i
> need this memory to be released when the object goes out of scope. is Lua's
> GC going to complicate this?

I'd prob allocate in C, and provide some functions (exported to lua) which
manipulate allocated memory.


Reply | Threaded
Open this post in threaded view
|

Re: Is Lua right for me?

Luiz Henrique de Figueiredo
In reply to this post by Chris Losinger
>	a) usable for people who aren't programmers (think engineering
>students). Lua looks like it might be ok here.

This kind of audience was one of the original targets of Lua.

>	b) fast enough to do simple arithmetic on enourmous data sets (2d
>image manipulation). it doesn't have to be real-time, but it shouldn't be in
>elephant time either. any opinions?

Such primitives are better implemented in C. See ImageKitchen in our uses page.

>	c) limitable. i need to be able to limit the language to keep users
>from going outside the scope of the host application. can this be done with
>Lua?

This is very easy to do, especially in Lua 4.0.
When you create a state, it's empty. You can export only the functions you
need (eg, your own image library) and/or export Lua libraries and explicitly
remove whatever is not wanted. This removal is easy to do too, and can be done
in Lua itself.

>	d) usable with huge data sets. i read a few messages about Lua's
>garbage collection system and images that give me doubts.. i want to create
>"image" objects that allocate data with Win32's GlobalAlloc function, and i
>need this memory to be released when the object goes out of scope. is Lua's
>GC going to complicate this?

If your images are stored in Lua variables as userdata, then you'll be
warned via GC tag methods when they are collected.
You can control when GC happens by setting the GC threshold.
Or you can use lua_newuserdata to allocate and register image objects for GC.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Is Lua right for me?

Nicolas Devillard
In reply to this post by Chris Losinger
> 	a) usable for people who aren't programmers (think engineering
> students). Lua looks like it might be ok here.

Yep, Lua is clearly a good choice for that (has been designed for that).

> 	b) fast enough to do simple arithmetic on enourmous data sets
> (2d image manipulation). it doesn't have to be real-time, but it
> shouldn't be in elephant time either. any opinions?

We do the same here. Image processing functions are programmed in
optimized ANSI C, which tends to get as fast as you get without touching
assembler.

The Lua part of our library is merely calling high-level functions in
sequence. Performance-wise, there is no difference between a Lua script
and a C main(), provided you do no pixel manipulation in Lua of course.


> 	d) usable with huge data sets. i read a few messages about Lua's
> garbage collection system and images that give me doubts.. i want to
> create "image" objects that allocate data with Win32's GlobalAlloc
> function, and i need this memory to be released when the object goes
> out of scope. is Lua's GC going to complicate this?

You need to take care in your library to provide a destructor for every
large object you allocate, and then rely on Lua's GC to call the
destructor. Our library processes several gigabytes worth of images
without hiccup.

Hope it helps,
-- 
Nicolas