From ed079572fc945e10d4c5677879c39384c2aec916 Mon Sep 17 00:00:00 2001 From: tomas Date: Wed, 15 Sep 2004 16:14:24 +0000 Subject: [PATCH] Adaptacao dos drivers para o novo modelo de pacotes de Lua 5.1. luaopen_luasql pack.loaded[] = luasql --- ls_pg.c | 27 ++++++++++++++++++++++++--- src/ls_mysql.c | 26 +++++++++++++++++++++++--- src/ls_oci8.c | 26 +++++++++++++++++++++++--- src/ls_odbc.c | 26 +++++++++++++++++++++++--- src/ls_sqlite.c | 26 +++++++++++++++++++++++--- 5 files changed, 116 insertions(+), 15 deletions(-) diff --git a/ls_pg.c b/ls_pg.c index c6dfcf9..a8881dc 100644 --- a/ls_pg.c +++ b/ls_pg.c @@ -3,7 +3,7 @@ ** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Carlos Cassino ** Tomas Guisasola, Eduardo Quintao ** See Copyright Notice in license.html -** $Id: ls_pg.c,v 1.19 2004/06/08 13:00:21 tomas Exp $ +** $Id: ls_pg.c,v 1.20 2004/09/15 16:14:24 tomas Exp $ */ #include @@ -495,6 +495,7 @@ static void create_metatables (lua_State *L) { luasql_createmeta (L, LUASQL_ENVIRONMENT_PG, environment_methods); luasql_createmeta (L, LUASQL_CONNECTION_PG, connection_methods); luasql_createmeta (L, LUASQL_CURSOR_PG, cursor_methods); + lua_pop (L, 3); } /* @@ -514,13 +515,33 @@ static int create_environment (lua_State *L) { ** Creates the metatables for the objects and registers the ** driver open method. */ -LUASQL_API int luaopen_luasql_postgres (lua_State *L) { +LUASQL_API int luaopen_luasqlpostgres (lua_State *L) { + const char *name; + int luasql; luasql_getlibtable (L); lua_pushstring(L, "postgres"); lua_pushcfunction(L, create_environment); lua_settable(L, -3); + luasql = lua_gettop (L); create_metatables (L); - return 0; + /* if Lua 5.0 then Set pack.loaded[name] = luasql */ + if (lua_isstring(L, 1)) + name = lua_tostring (L, 1); + else { + lua_getglobal (L, "arg"); + lua_rawgeti (L, -1, 1); + name = lua_tostring (L, -1); + lua_pop (L, 2); + } + lua_getglobal (L, "pack"); + lua_pushliteral (L, "loaded"); + lua_gettable (L, -2); + lua_pushstring (L, name); + lua_pushvalue (L, luasql); + lua_settable (L, -3); /* pack.loaded[name] = luasql */ + lua_pop (L, 2); + + return 1; } diff --git a/src/ls_mysql.c b/src/ls_mysql.c index 0973016..b46aeb4 100644 --- a/src/ls_mysql.c +++ b/src/ls_mysql.c @@ -2,7 +2,7 @@ ** LuaSQL, MySQL driver ** Authors: Eduardo Quintao ** See Copyright Notice in license.html -** $Id: ls_mysql.c,v 1.12 2004/09/15 15:58:25 tomas Exp $ +** $Id: ls_mysql.c,v 1.13 2004/09/15 16:14:24 tomas Exp $ */ #include @@ -493,13 +493,33 @@ static int create_environment (lua_State *L) { ** Creates the metatables for the objects and registers the ** driver open method. */ -LUASQL_API int luaopen_luasql_mysql (lua_State *L) { +LUASQL_API int luaopen_luasqlmysql (lua_State *L) { + const char *name; + int luasql; luasql_getlibtable (L); lua_pushstring(L, "mysql"); lua_pushcfunction(L, create_environment); lua_settable(L, -3); + luasql = lua_gettop (L); create_metatables (L); - return 0; + /* if Lua 5.0 then Set pack.loaded[name] = luasql */ + if (lua_isstring(L, 1)) + name = lua_tostring (L, 1); + else { + lua_getglobal (L, "arg"); + lua_rawgeti (L, -1, 1); + name = lua_tostring (L, -1); + lua_pop (L, 2); + } + lua_getglobal (L, "pack"); + lua_pushliteral (L, "loaded"); + lua_gettable (L, -2); + lua_pushstring (L, name); + lua_pushvalue (L, luasql); + lua_settable (L, -3); /* pack.loaded[name] = luasql */ + lua_pop (L, 2); + + return 1; } diff --git a/src/ls_oci8.c b/src/ls_oci8.c index dc2279f..35f60d2 100644 --- a/src/ls_oci8.c +++ b/src/ls_oci8.c @@ -2,7 +2,7 @@ ** LuaSQL, Oracle driver ** Authors: Tomas Guisasola, Leonardo Godinho ** See Copyright Notice in license.html -** $Id: ls_oci8.c,v 1.18 2004/09/15 15:58:25 tomas Exp $ +** $Id: ls_oci8.c,v 1.19 2004/09/15 16:14:24 tomas Exp $ */ #include @@ -843,13 +843,33 @@ static void create_metatables (lua_State *L) { ** Creates the metatables for the objects and registers the ** driver open method. */ -LUASQL_API int luaopen_luasql_oracle (lua_State *L) { +LUASQL_API int luaopen_luasqloracle (lua_State *L) { + const char *name; + int luasql; luasql_getlibtable (L); lua_pushstring(L, "oracle"); lua_pushcfunction(L, create_environment); lua_settable(L, -3); + luasql = lua_gettop (L); create_metatables (L); - return 0; + /* if Lua 5.0 then Set pack.loaded[name] = luasql */ + if (lua_isstring(L, 1)) + name = lua_tostring (L, 1); + else { + lua_getglobal (L, "arg"); + lua_rawgeti (L, -1, 1); + name = lua_tostring (L, -1); + lua_pop (L, 2); + } + lua_getglobal (L, "pack"); + lua_pushliteral (L, "loaded"); + lua_gettable (L, -2); + lua_pushstring (L, name); + lua_pushvalue (L, luasql); + lua_settable (L, -3); /* pack.loaded[name] = luasql */ + lua_pop (L, 2); + + return 1; } diff --git a/src/ls_odbc.c b/src/ls_odbc.c index 88578bf..b372e2e 100644 --- a/src/ls_odbc.c +++ b/src/ls_odbc.c @@ -3,7 +3,7 @@ ** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Diego Nehab, ** Tomas Guisasola ** See Copyright Notice in license.html -** $Id: ls_odbc.c,v 1.22 2004/09/15 15:58:25 tomas Exp $ +** $Id: ls_odbc.c,v 1.23 2004/09/15 16:14:24 tomas Exp $ */ #include @@ -698,13 +698,33 @@ static int create_environment (lua_State *L) { ** Creates the metatables for the objects and registers the ** driver open method. */ -LUASQL_API int luaopen_luasql_odbc(lua_State *L) { +LUASQL_API int luaopen_luasqlodbc (lua_State *L) { + const char *name; + int luasql; luasql_getlibtable (L); lua_pushstring(L, "odbc"); lua_pushcfunction(L, create_environment); lua_settable(L, -3); + luasql = lua_gettop (L); create_metatables (L); - return 0; + /* if Lua 5.0 then Set pack.loaded[name] = luasql */ + if (lua_isstring(L, 1)) + name = lua_tostring (L, 1); + else { + lua_getglobal (L, "arg"); + lua_rawgeti (L, -1, 1); + name = lua_tostring (L, -1); + lua_pop (L, 2); + } + lua_getglobal (L, "pack"); + lua_pushliteral (L, "loaded"); + lua_gettable (L, -2); + lua_pushstring (L, name); + lua_pushvalue (L, luasql); + lua_settable (L, -3); /* pack.loaded[name] = luasql */ + lua_pop (L, 2); + + return 1; } diff --git a/src/ls_sqlite.c b/src/ls_sqlite.c index a9ca35c..1820e37 100644 --- a/src/ls_sqlite.c +++ b/src/ls_sqlite.c @@ -2,7 +2,7 @@ ** LuaSQL, SQLite driver ** Author: Tiago Dionizio, Eduardo Quintao ** See Copyright Notice in license.html -** $Id: ls_sqlite.c,v 1.2 2004/09/15 15:58:25 tomas Exp $ +** $Id: ls_sqlite.c,v 1.3 2004/09/15 16:14:24 tomas Exp $ */ #include @@ -540,14 +540,34 @@ static int create_environment (lua_State *L) ** Creates the metatables for the objects and registers the ** driver open method. */ -LUASQL_API int luaopen_luasql_sqlite(lua_State *L) +LUASQL_API int luaopen_luasqlsqlite(lua_State *L) { + const char *name; + int luasql; luasql_getlibtable (L); lua_pushliteral(L, "sqlite"); lua_pushcfunction(L, create_environment); lua_settable(L, -3); + luasql = lua_gettop (L); create_metatables (L); - return 0; + /* if Lua 5.0 then Set pack.loaded[name] = luasql */ + if (lua_isstring(L, 1)) + name = lua_tostring (L, 1); + else { + lua_getglobal (L, "arg"); + lua_rawgeti (L, -1, 1); + name = lua_tostring (L, -1); + lua_pop (L, 2); + } + lua_getglobal (L, "pack"); + lua_pushliteral (L, "loaded"); + lua_gettable (L, -2); + lua_pushstring (L, name); + lua_pushvalue (L, luasql); + lua_settable (L, -3); /* pack.loaded[name] = luasql */ + lua_pop (L, 2); + + return 1; }