lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>I would like to propose a standard lua library. Written in Lua.

This is a good idea, because as has been mentioned in previous posts, Lua does
lack wider library support for scripting.

Nevertheless, I suggest some other name be chosen to avoid confusion with the
"standard libraries" that come with Lua, that is liblualib.a in Unix-speak.

>How to include:
>dofile("stdlua.lua")
>
>stdlua.lua should only expose a single global variable "stdlua" and all
>functions should be members in stdlua.

I suggest a more flexible scheme: in stdlua.lua (or whatever the name is),
test whether a table called "stdlua" exists. If it does, then stdlua.lua should
define only those functions whose name appear in the table. In this way, users
can choose the functions they need.

Example:

stdlua={clone=1, strtrim=1}
dofile"stdlua.lua"

In "stdlua.lua":

local select=stdlua
local L=settag({},newtag())
settagmethod(tag(L),"settable", function (i,v)
  if not select or stdlua[i] then rawset(L,i,v) end
end)

function L.clone() ... end 
function L.strtrim() ... end 
function L.abort() ... end 

...

stdlua=L
return L

--lhf