[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Observations/Questions
- From: Norman Ramsey <nr@...>
- Date: Thu, 08 Jul 1999 12:48:57 -0400
> 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.
Norman