POV-Ray : Newsgroups : povray.pov4.discussion.general : Next Generation SDL: What's wrong with Lua, JavaScript, ... : Next Generation SDL: What's wrong with Lua, JavaScript, ... Server Time
2 Mar 2024 02:22:29 EST (-0500)
  Next Generation SDL: What's wrong with Lua, JavaScript, ...  
From: clipka
Date: 11 Apr 2009 06:40:00
Message: <web.49e0730bfb1ed94319d16df90@news.povray.org>
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.)


Post a reply to this message

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