Ken Rawlings | 8 Jul 01:14 1999
Picon
Picon

Re: Lua Observations/Questions

> What kind of functions for handling raw binary data would yoou like to see?

   Equivalents to the C bitwise operators would be really handy.

> I think that the existence of tag methods for getglobal makes it impossible
> for Lua to be tail recursive, because the tag method may return anything in

   Overall, that seems like a fair tradeoff, given how incredibly useful
   it is to be able to set tag methods for getglobal.

   I have a quick question on Lua datatypes. What is the preferred method
   for generating and using lists in Lua? Originally I thought that the
   following could be used:

   l = { 1, 2, 4, 5 }

   However, it appears that Lua doesn't have a method for adding or 
   deleting data at an arbitrary position. For instance, how can you
   add '3' to the table above between '1' and '2'? Along the same lines,
   how can you delete the '4'? I've read through the manual to no
   avail. Am I missing something?

Thanks,
_Ken 

Picon

Re: Lua Observations/Questions

>From lua-l <at> tecgraf.puc-rio.br Wed Jul  7 20:35:02 1999
>From: Ken Rawlings <krawling <at> shooter.bluemarble.net>

>   I have a quick question on Lua datatypes. What is the preferred method
>   for generating and using lists in Lua? Originally I thought that the
>   following could be used:
>
>   l = { 1, 2, 4, 5 }
>
>   However, it appears that Lua doesn't have a method for adding or 
>   deleting data at an arbitrary position. For instance, how can you
>   add '3' to the table above between '1' and '2'? Along the same lines,
>   how can you delete the '4'? I've read through the manual to no
>   avail. Am I missing something?

Lua 3.2 (to be released in a couple of days) has a new built-in function
tinsert that does this. (You can try it now with 3.2 beta.)
--lhf

Ken Rawlings | 8 Jul 02:37 1999
Picon
Picon

Re: Lua Observations/Questions

On Wed, 7 Jul 1999, Luiz Henrique de Figueiredo wrote:
> Lua 3.2 (to be released in a couple of days) has a new built-in function
> tinsert that does this. (You can try it now with 3.2 beta.)

   Thanks, tinsert and tremove are exactly what I was looking for. Looking
   at the documentation, though, i'm a little concerned, given the
   lua equivalent for tinsert. That source implies that tinsert copies
   every object at a given position(after the insert) to that position + 1,
   so that l[3] gets copied to l[4], making room for something at l[3]. 
   Doesn't this make tinsert a O(n) operation, and thus prohibitive for
   dynamic additions to large data sets?

Thanks,
Ken

Steve Dekorte | 8 Jul 04:10 1999

Re: Lua Observations/Questions

Ken Rawlings <krawling <at> shooter.bluemarble.net> wrote:
> On Wed, 7 Jul 1999, Luiz Henrique de Figueiredo wrote:
> > Lua 3.2 (to be released in a couple of days) has a new built-in function
> > tinsert that does this. (You can try it now with 3.2 beta.)
> 
>    Thanks, tinsert and tremove are exactly what I was looking for. Looking
>    at the documentation, though, i'm a little concerned, given the
>    lua equivalent for tinsert. That source implies that tinsert copies
>    every object at a given position(after the insert) to that position + 1,
>    so that l[3] gets copied to l[4], making room for something at l[3]. 
>    Doesn't this make tinsert a O(n) operation, and thus prohibitive for
>    dynamic additions to large data sets?

I was thinking the same thing. 
Has anyone written their own list data type or list API?
Hmmm. If someone wrote a simple API like:

 list_new() returns listPointer
 list_insert(void *listPointer, lua_Object item)
 list_remove(listPointer, int index)
 list_at(listPointer, int index) returns lua_Object
 list_destroy(void *listPointer)

Then a simple lua list object would be easy to implement:

listProto = {
 listPointer = nil,
 clone = function (self) return clone(self):init() end,
 init  = function (self) self.listPointer = list_new() return self end,
 insertAt_ = function (self, o) list_insert(self.listPointer, o) end,
(Continue reading)

Picon

Re: Lua Observations/Questions

>From lua-l <at> tecgraf.puc-rio.br Wed Jul  7 21:55:53 1999
>From: Ken Rawlings <krawling <at> shooter.bluemarble.net>

>   Thanks, tinsert and tremove are exactly what I was looking for. Looking
>   at the documentation, though, i'm a little concerned, given the
>   lua equivalent for tinsert. That source implies that tinsert copies
>   every object at a given position(after the insert) to that position + 1,
>   so that l[3] gets copied to l[4], making room for something at l[3]. 
>   Doesn't this make tinsert a O(n) operation, and thus prohibitive for
>   dynamic additions to large data sets?

Right. They do shift everything.
However, it's done in C, not in Lua, and so it should be fast enough for
tables with say 1000 elements.
If you're really worried about this *and* have *really* large tables,
consider instead a linked list in Lua.
--lhf

Picon

Re: Lua Observations/Questions

>From lua-l <at> tecgraf.puc-rio.br Wed Jul  7 23:19:42 1999
>From: Steve Dekorte <steve <at> dekorte.com>

>Has anyone written their own list data type or list API?
>Hmmm. If someone wrote a simple API like:
>
> list_new() returns listPointer
> list_insert(void *listPointer, lua_Object item)
> list_remove(listPointer, int index)

if listPointer is the head, how would these not be O(n)?

> list_at(listPointer, int index) returns lua_Object

you have to be careful if you're keeping a list of lua_Object.
you should keep a list of references instead and still be careful unless
you lock everything.
--lhf

Picon

[ANNOUNCE] Lua 3.2 -- an extensible extension language

* What is Lua?
  ------------
  Lua is a programming language originally designed for extending applications,
  but also frequently used as a general-purpose, stand-alone language.
  Lua combines simple procedural syntax (similar to Pascal) with powerful
  data description constructs based on associative arrays and extensible
  semantics. Lua is dynamically typed, interpreted from bytecodes, and has
  automatic memory management, making it ideal for configuration, scripting,
  and rapid prototyping.

  Lua is implemented as a small library of C functions, written in ANSI C,
  and compiles unmodified in all known platforms. The implementation goals
  are simplicity, efficiency, portability, and low embedding cost.

  Lua was awarded the first prize (technological category) in the Second Compaq 
  Award for Research and Development in Computer Science in 1997. This award
  is a joint venture of Compaq Computer in Brazil, the Brazilian Ministry of
  Science and Technology, and the Brazilian Academy of Sciences.

  Lua has been used in many different projects around the world.
  For a short list, see http://www.tecgraf.puc-rio.br/lua/uses.html

* New in version 3.2
  ------------------
  + redirected all output in Lua's core to _ERRORMESSAGE and _ALERT.
  + increased limit on the number of constants and globals per function
    (from 2^16 to 2^24).
  + debugging info (lua_debug and hooks) moved into lua_state and new API
    functions provided to get and set this info.
  + new debug lib gives full debugging access within Lua.
(Continue reading)

Norman Ramsey | 8 Jul 18:48 1999

Re: Lua Observations/Questions

 > Has anyone written their own list data type or list API?
 > Hmmm. If someone wrote a simple API like:
 > 
 >  list_new() returns listPointer
 >  list_insert(void *listPointer, lua_Object item)
 >  list_remove(listPointer, int index)
 >  list_at(listPointer, int index) returns lua_Object
 >  list_destroy(void *listPointer)
 > 
 > Then a simple lua list object would be easy to implement:
 > 
 > listProto = {
 >  listPointer = nil,
 >  clone = function (self) return clone(self):init() end,
 >  init  = function (self) self.listPointer = list_new() return self end,
 >  insertAt_ = function (self, o) list_insert(self.listPointer, o) end,
 >  removeAt_ = function (self, o) list_remove(self.listPointer, o) end,
 >  at_ = function (self, index) return list_at(self.listPointer, index) end,
 >  destroy = function (self) list_destroy(self.listPointer) end,
 > }
 > 
 > and tag listProto to call destroy before instances get garbage collected.

To my mind, the most significant defect of Lua (and there are very few
such!) is that it's hard to add a new primitive type to the language.

FYI, there are a bunch of excellent abstract data types, including
lists, in Dave Hanson's book `C Interfaces and Implementations'.  I
have bound some of these for use inside Lua.  The software is
available free from http://www.cs.princeton.edu/software/cii.
(Continue reading)

David Jeske | 8 Jul 19:39 1999
Picon

Re: Lua Observations/Questions

On Thu, Jul 08, 1999 at 01:50:10PM -0300, Norman Ramsey wrote:
> To my mind, the most significant defect of Lua (and there are very few
> such!) is that it's hard to add a new primitive type to the language.

It's not too hard to add custom "complex" data-types in my
experience. Basic datatypes are a bit harder.

For example, I want a proper boolean type. I want a real boolean type,
and I have not yet found a suitable solution because even if I make
"proper" TRUE/FALSE values:
  1) I can't control the output of the equality operator so that
     it returns my TRUE and FALSE values
  2) I can't control the way conditionals interpret their values
     so that they see my FALSE as false.

The reason I want a proper boolean type is this:

I use a "parent inheritence scheme" similar to that explained in some
older Lua documentation. This makes object methods and values chain up
to the next parent in the chain. However, because the "nil" value is
"not present" I can never store a nil value to override another
value. Consider this scenerio:

-- Obj sets up my parent chaining mechanism

parent = Obj{ value = 1 }
child = Obj{ parent = parent }

print child.value    -- yeilds 1

(Continue reading)

David Jeske | 8 Jul 19:47 1999
Picon

Re: Lua Observations/Questions

Sorry for the followup to my own post, but I forgot to add an
important detail.

On Thu, Jul 08, 1999 at 10:39:23AM -0700, David Jeske wrote:
> I use a "parent inheritence scheme" similar to that explained in some
> older Lua documentation. This makes object methods and values chain up
> to the next parent in the chain. However, because the "nil" value is
> "not present" I can never store a nil value to override another
> value. Consider this scenerio:
> 
> -- Obj sets up my parent chaining mechanism
> 
> parent = Obj{ value = 1 }
> child = Obj{ parent = parent }
> 
> print child.value    -- yeilds 1
> 
> child.value = 2
> print child.value    -- yeilds 2
> 
> child.value = nil
> print child.value    -- yeilds 1   <<-- not what I wanted

I would be completely fine with all of this, if I could use a proper
boolean type which included real "TRUE" and "FALSE" values. In order
for me to do this, I need to be able to have all binary operators
return my real TRUE/FALSE values, and I need to have all comparison
attempts honor my FALSE as false. Unless I'm mistaken that means I
would need:

(Continue reading)


Gmane