lua-users home
lua-l archive

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

Good day

I am trying to learn Lua and friends.  Trying to test a simple,
little browser app, I took subset of test.lp (the one that comes with
Kepler).  It works fine as a form, returning POST values ok.  So, as a
next step, I included code to load the returned POST values into a
little SQLite3 database.  Now, the Lua script loads values into the
SQLite3 just fine as a standalone script, but once I included the database
in to the Luapage, the following is reported:
SQlite3browser.lp:33: attempt to index global 'luasql' (a nil value)
stack traceback:
 SQlite3browser.lp:33: in function 'prog'
 C:\LuaRocks/rocks//cgilua/5.1.3-1/lua/cgilua\lp.lua:132: in function
 C:\LuaRocks/rocks//cgilua/5.1.3-1/lua/cgilua.lua:282: in function
 (tail call): ?
 (tail call): ?
stack traceback:
 C:\LuaRocks/rocks//cgilua/5.1.3-1/lua/cgilua.lua:161: in function
 ...:\LuaRocks/rocks//coxpcall/1.13.0-1/lua/coxpcall.lua:24: in
function <...:\LuaRocks/rocks//coxpcall/1.13.0-1/lua/coxpcall.lua:22>
 (tail call): ?
 (tail call): ?
 C:\LuaRocks/rocks//cgilua/5.1.3-1/lua/cgilua.lua:169: in function
 C:\LuaRocks/rocks//cgilua/5.1.3-1/lua/cgilua.lua:629: in function
 C:\LuaRocks/rocks//wsapi/1.1-2/lua/wsapi\sapi.lua:49: in function
 (tail call): ?

I suspect all the messages following the first line will not appear if I
can solve that 'index global 'luasql' issue.

The script follows:
#!/usr/bin/env cgilua.cgi

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns=""; xml:lang="en" lang="en">
   <title>CGILua Test Updating SQLite3</title>


<h2>Form Handling</h2>

Entering values on this form should display them as values in the first


<form method="post"
   <label>User name : </label><input name="name" maxlength="20"
   <label>Age : </label><input name="age" maxlength="3" size="3">
   <input type="submit" value="Post it">

The values should show the previous POST

Values: Username = <%= or "(not set)"%>, Age = <%=
cgilua.POST.age or "(not set)"%>

<% require ("luasql.sqlite3") --<----<------<----<--- THIS IS LINE 33
local env = (luasql.sqlite3())
conn = env:connect("luasql-test")
nm =
ag = cgilua.POST.age
assert(conn:execute("insert into people values('" ..nm .."', '"


<p>Today is: <%= %></p>


Could someone please explain what I am doing wrong here?  Also, I
thought of pointing to a separate database script by supplying an
"action" and script name to the form, but am unsure how to pass the POST
values to the script in such a case.

Jasper Cook

View this message in context:
Sent from the Lua - General mailing list archive at