Thanks for the feedback.  I get no errors when I implement your check below.  
The ‘require’ call is not failing.

As I said in my original post, this code works fine in my application:

require "luasql.sqlite3"

env = luasql.sqlite3()
conn = env:connect("testsqlite.db3")

assert(conn:execute("create table if not exists tbl1(one, two)"))
assert(conn:execute("insert into tbl1 values('hello!',10)"))
assert(conn:execute("insert into tbl1 values('goodbye',20)"))

conn:close()
env:close()

The create table and inserts actually happen and the output file contains the 
data.  So I know for sure that the require is working and that the module is 
loaded and working in my application.

This code fails in my application, but succeeds from the lua command line:

require "luasql.sqlite3"

env = luasql.sqlite3()
conn = env:connect("testsqlite.db3")

assert(conn:execute("create table if not exists tbl1(one, two)"))
assert(conn:execute("insert into tbl1 values('hello!',10)"))
assert(conn:execute("insert into tbl1 values('goodbye',20)"))

cursor = assert(conn:execute("select * from tbl1"))
row = {}
while cursor:fetch(row) do
      print(table.concat(row, '|'))
end

cursor:close()
conn:close()
env:close()

I get an unhandled exception (access violation) at lua_pcall(L,0,0,0).  I don’t 
think this has anything to do with mixing lua errors and exceptions.

RW

Ron Wilson, Engineering Project Lead
(o) 434.455.6453, (m) 434.851.1612, www.harris.com

HARRIS CORPORATION   |   RF Communications Division                             
                                  assuredcommunications™

From: kepler-project-boun...@lists.luaforge.net 
[mailto:kepler-project-boun...@lists.luaforge.net] On Behalf Of Ignacio Burgueño
Sent: Thursday, October 21, 2010 1:36 PM
To: Kepler Project mailing list
Subject: Re: [Kepler-Project] help with luasql.sqlite in my c++ code

If I understood correctly, your script works fine using the standalone 
interpreter, but fails to do so when you run it from your application, right?

The error handling in your C++ seems wrong.
You load your script, pcall it and if there is an error, you call lua_error. 
That will invoke your panic function that gets the message and throws a C++ 
exception. You're mixing Lua errors and exceptions. Nothing good will come out 
of that :D

I think that your Lua script causes a runtime error, and the application blows 
up when dealing with it. Probably the require call is failing.

Try this, instead of require "luasql.sqlite3"
do
local ok, err = pcall(require, "luasql.sqlite3")
if not ok then
    print(err)
end

Let's see if the error shows up here. Also you can add some printf's in your 
code before throwing exceptions to see what's going on.

Regards,
Ignacio

<<inline: image001.png>>

_______________________________________________
Kepler-Project mailing list
Kepler-Project@lists.luaforge.net
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/

Reply via email to