lua-users home
lua-l archive

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


	Hi Chris,

I am trying to figure out how to use sessions with CGILUA.
        Are you sure the session library is correctly configured?

No, how do I configure the session library? I don't believe the
configuration of any libraries was mentioned in the guides I read, or
any other documentation, but I could have missed something.
	You should add the following lines to your configuration
file (/LUA_PATH/cgilua/config.lua):

require"cgilua.session"
cgilua.session.setsessiondir ("/tmp/cgilua/") -- you should edit this!
cgilua.addopenfunction (cgilua.session.open)
cgilua.addclosefunction (cgilua.session.close)

	This will enable the use of the library to all scripts
processed by CGILua in your web server.  If you want to enable it on
demand, you could change the two last lines above by the following:

cgilua.enablesession = function ()
    cgilua.session.open ()
    cgilua.addclosefunction (cgilua.session.close)
end

	This code will provide the function `cgilua.enablesession'
(or the name you want) which should be called at the beginning of any
script that wants to use sessions.

I guess this is probably just because something has changed between
versions, but I can't figure out how to use sessions just by looking
at the docs. I don't know if/when any of those functions need to be
called.
        If you're not sure about what version you have installed,
please download the most recent one (5.0) and make sure it is correctly
installed.
        The session library requires that function cgilua.session.open
is called before the script is executed and function cgilua.session.close
is called after the script ends.  Those functions will manage the table
cgilua.data (new versions will call it cgilua.session.data), by obtaining
serialized data from a session file (function open) and storing it back to
the file when the script ends (function close).
        A script that wants to use this feature just have to read and
write data to this table and -- very important -- always use cgilua.mkurlpath
to build any link in the resulting HTML document.

Whenever I try to do anything with cgilua.session it tells me it is
nil. Is this because it isn't configured properly?  as a shot in the
dark I tried to require("cgilua.session"). although it allowed that
line it didn't have any effect. I still get the error when trying to
access *anything* in the cgilua.session table.
	You could `require"cgilua.session"' in your script but you'll
have to initialize and finalize the library, just as the above function
`enablesession' does.  An example could be (untested):

require"cgilua.session"
cgilua.setsessiondir("/tmp/cgilua/")
cgilua.session.open ()

-- your script

cgilua.session.close ()

	But pay attention: if an error occurs before the call to
`cgilua.session.close', then it will not be called and the changes to
the session won't be saved.  The use of `cgilua.addclosefunction' avoids
this problem.

	Regards,
		Tomas