POV-Ray : Newsgroups : povray.pov4.discussion.general : Next Generation SDL: What's wrong with Lua, JavaScript, ... : Re: Next Generation SDL: What's wrong with Lua, JavaScript, ... Server Time
28 Apr 2024 20:09:38 EDT (-0400)
  Re: Next Generation SDL: What's wrong with Lua, JavaScript, ...  
From: SharkD
Date: 11 Apr 2009 14:29:46
Message: <49e0e19a@news.povray.org>
clipka wrote:
> I've done some pondering over Lua, wondering how it would be used to describe a
> POV scene.
> 
> I think it doesn't work out. Neither does JavaScript, or many other languages
> for that matter. Here's why:
> 
> POV-Ray is basically all about creating geometric objects in 3D space with
> certain properties. The SDL should faciliate this.
> 
> Let's first look at the average mainstream language; Leaving aside syntax
> details and focusing only on "grammar" instead, here's how this would be coded
> in the average OO-enabled language:
> 
> - Create a new sphere named "fooSphere" at <x,y,z> with radius r.
> - Create a new texture named "fooTexture".
> - Create a new pigment named "fooPigment" with color <r,g,b>.
> - Assign to "fooTexture" the pigment "fooPiment".
> - Assign to "fooSphere" the texture "fooSphere".
> - Translate "fooSphere" by <x,y,z>.
> - Add to the scene the object "fooSphere".
> 
> Yuck. We all know this sucks.
> 
> So what *exactly* do we want? I think what we need is a grammar as close as
> possible to this:
> 
> - With the scene...
> -   Add to it a new sphere at <x,y,z> with radius r, and with that...
> -     Assign to it a new texture, and with that...
> -       Assign to it a new pigment with color <r,b,b>.
> -   Translate it by <x,y,z>
> 
> Let's have a look at how this could be approximated with Lua:
> 
> We could pre-define special functions "scene", "sphere", "texture", "pigment"
> and "translate", each taking the basic parameters, plus a variable list of
> "modifiers", which in turn would be e.g. objects, textures, pigments or
> transformations. This would giving us (for now ignoring the question of how
> exactly to build vectors):
> 
>   scene (
>     sphere ( <x,y,z>, r,
>       texture ( pigment ( color <r,g,b> ) ),
>       translate ( <x,y,z> )
>     )
>   );
> 
> Nice, isn't it?
> 
> Well, no. To see why, let's look at this one:
> 
> - With the scene...
> -   Add to it a new blob, and with that...
> -     Assign to it a new threshold t.
> -     Add to it a new blob-sphere at <x,y,z> with radius r and strength s.
> 
> How would this translate in our Lua approach?
> 
>   scene (
>     blob (
>       threshold(t),
>       blob.sphere ( <x,y,z>, r, s )
>     )
>   );
> 
> Obviously we forgot that "sphere" and "sphere" may mean two different things,
> depending on context. (Granted, they're not very far apart; but it outlines the
> underlying general problem.)
> 
> So what we did above was to exploit Lua syntax to come up with a shortcut for "a
> new FOO, and with that... do BAR. do FUZZ.", when in fact what we *precisely*
> want to express is "a new FOO, and with that... do FOO-BAR, do FOO-FUZZ".
> 
> I do not know any single scripting language providing syntactical sugar to
> express exactly that in a concise manner - or at least providing a mechanism
> that can be exploited to that end.
> 
> If anyone knows a comparatively well-established language providing exactly
> that, please speak up. But I guess we really need to roll our own. (Though I
> guess the core of Lua could still serve as a good basis, i.e. the virtual
> machine and probably a good deal of the parser.)
> 
> 

I didn't quite understand your post. But, how about hash arrays?

scene =
{
	objects =
	{
		My_Sphere =
		{
			type = "sphere",
			location = <x,y,z>,
			radius = r,
			texture =
			{
				pigment =
				{
					color = <r,g,b>
				}
			},
			transformation =
			{
				translate = <x,y,z>
			}
		}
	}
};

This syntax is more akin to what you find in *markup languages*, but you 
can still easily modify the scene. Alternately, we could differentiate 
the content and behavior by using separate sections and languages for 
each (i.e. HTML and JavaScript in web pages).

However, I prefer using one language, since there's nothing a markup 
language like XML can do that a scripting language can't also do by 
using literal (i.e. terse or shorthand) syntax.

-Mike


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.