lua-users home
lua-l archive

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


>   I have a set of scripts written in lua. For their "communication", I
> serialize state to files blah_xyz_timestamp such that
> 
> local data = dofile("blah_xyz_timestamp")
> 
>   brings the state back.
> 
>   Now, problem is
> (1) I have lots and lots of these serialized data (> 10K files)
> (2) I want to have meta-tags attached to each file blah_xyz_timestamp ... that
> don't nicely fit into an object filename
> 
>   So basically, what I really want -- is a database ... that stores seiralized
> lua data. (So I can do stuff like
> 
> SELECT * from DB where function(tag) return (tag.name == "hello") and (bar_func
> (tag.config)) end;
> 
>   [where for each object, I have a table associated with it that stores meta
> data, and I can select objects based on this meta data].
> 
> Now, my current solution ... is to stuff all this into MySQL ... but that seems
> inelegant. There ought to be a better solution. If you've dealt with something
> similar, I'd love to hear about your experiences.

If you don't mind using PostgreSQL, one solution is to use PL/Lua:

test=# create table beowulf (state text, tag text);
CREATE TABLE
test=# insert into beowulf values ('foo', '{name="beowulf"}');
INSERT 0 1
test=# insert into beowulf values ('bar', '{name="hello"}');
INSERT 0 1
test=# create function setuptag() returns void as $$
test$# bar_func = function (config)
test$#   -- do some stuff
test$#   return true
test$# end
test$# $$ language plluau;
CREATE FUNCTION
test=# select setuptag(); -- define bar_func
 setuptag 
----------
 
(1 row)

test=# create function checktag (tag text) returns boolean as $$
test$# local tt = loadstring("return " .. tag)()
test$# return tt.name == "hello" and bar_func(tt.config)
test$# $$ language plluau;
CREATE FUNCTION
test=# select * from beowulf where checktag(tag);
 state |      tag       
-------+----------------
 bar   | {name="hello"}
(1 row)

You can put setuptag in a module and setup a pllua.init entry so that bar_func
is available whenever your db starts (please check the docs for more
information).

Cheers,
Luis

-- 
Computers are useless. They can only give you answers.
                -- Pablo Picasso

-- 
Luis Carvalho (Kozure)
lua -e 'print((("lexcarvalho@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'