mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 10:18:31 +00:00
Add sqlite3 support to Lua scripts in redbean.
This commit is contained in:
parent
067c14891f
commit
b3a08d9286
3 changed files with 24 additions and 7 deletions
|
@ -26,13 +26,17 @@
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
#include <stdlib.h>
|
// attribution in binary form
|
||||||
#include <string.h>
|
asm(".ident\t\"\\n\\n\
|
||||||
#include <assert.h>
|
lsqlite3 (MIT License)\\n\
|
||||||
|
Copyright 2002-2016 Tiago Dionizio, Doug Currie\"");
|
||||||
|
asm(".include \"libc/disclaimer.inc\"");
|
||||||
|
|
||||||
#define LUA_LIB
|
#include "libc/calls/weirdtypes.h"
|
||||||
#include "lua.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "lauxlib.h"
|
|
||||||
|
#include "third_party/lua/lua.h"
|
||||||
|
#include "third_party/lua/lauxlib.h"
|
||||||
|
|
||||||
#if LUA_VERSION_NUM > 501
|
#if LUA_VERSION_NUM > 501
|
||||||
/*
|
/*
|
||||||
|
@ -56,7 +60,7 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "sqlite3.h"
|
#include "third_party/sqlite3/sqlite3.h"
|
||||||
|
|
||||||
/* compile time features */
|
/* compile time features */
|
||||||
#if !defined(SQLITE_OMIT_PROGRESS_CALLBACK)
|
#if !defined(SQLITE_OMIT_PROGRESS_CALLBACK)
|
||||||
|
@ -1219,6 +1223,10 @@ static int db_create_collation(lua_State *L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// comment out `db_load_extension`, as cosmo can't resolve
|
||||||
|
// `sqlite3_enable_load_extension`, since it's built with
|
||||||
|
// `SQLITE_OMIT_LOAD_EXTENSION`, which disables extensions.
|
||||||
|
#if 0
|
||||||
/* Thanks to Wolfgang Oertl...
|
/* Thanks to Wolfgang Oertl...
|
||||||
*/
|
*/
|
||||||
static int db_load_extension(lua_State *L) {
|
static int db_load_extension(lua_State *L) {
|
||||||
|
@ -1246,6 +1254,7 @@ static int db_load_extension(lua_State *L) {
|
||||||
sqlite3_free(errmsg);
|
sqlite3_free(errmsg);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** trace callback:
|
** trace callback:
|
||||||
|
@ -2238,7 +2247,9 @@ static const luaL_Reg dblib[] = {
|
||||||
{"create_function", db_create_function },
|
{"create_function", db_create_function },
|
||||||
{"create_aggregate", db_create_aggregate },
|
{"create_aggregate", db_create_aggregate },
|
||||||
{"create_collation", db_create_collation },
|
{"create_collation", db_create_collation },
|
||||||
|
#if 0
|
||||||
{"load_extension", db_load_extension },
|
{"load_extension", db_load_extension },
|
||||||
|
#endif
|
||||||
|
|
||||||
{"trace", db_trace },
|
{"trace", db_trace },
|
||||||
{"progress_handler", db_progress_handler },
|
{"progress_handler", db_progress_handler },
|
||||||
|
|
|
@ -42,6 +42,7 @@ TOOL_NET_DIRECTDEPS = \
|
||||||
NET_HTTP \
|
NET_HTTP \
|
||||||
THIRD_PARTY_GETOPT \
|
THIRD_PARTY_GETOPT \
|
||||||
THIRD_PARTY_LUA \
|
THIRD_PARTY_LUA \
|
||||||
|
THIRD_PARTY_SQLITE3 \
|
||||||
THIRD_PARTY_REGEX \
|
THIRD_PARTY_REGEX \
|
||||||
THIRD_PARTY_ZLIB \
|
THIRD_PARTY_ZLIB \
|
||||||
TOOL_DECODE_LIB
|
TOOL_DECODE_LIB
|
||||||
|
@ -51,6 +52,7 @@ TOOL_NET_DEPS := \
|
||||||
|
|
||||||
o/$(MODE)/tool/net/net.pkg: \
|
o/$(MODE)/tool/net/net.pkg: \
|
||||||
$(TOOL_NET_OBJS) \
|
$(TOOL_NET_OBJS) \
|
||||||
|
o/tool/net/lsqlite3.o \
|
||||||
$(foreach x,$(TOOL_NET_DIRECTDEPS),$($(x)_A).pkg)
|
$(foreach x,$(TOOL_NET_DIRECTDEPS),$($(x)_A).pkg)
|
||||||
|
|
||||||
o/$(MODE)/tool/net/%.com.dbg: \
|
o/$(MODE)/tool/net/%.com.dbg: \
|
||||||
|
@ -64,6 +66,7 @@ o/$(MODE)/tool/net/%.com.dbg: \
|
||||||
o/$(MODE)/tool/net/redbean.com.dbg: \
|
o/$(MODE)/tool/net/redbean.com.dbg: \
|
||||||
$(TOOL_NET_DEPS) \
|
$(TOOL_NET_DEPS) \
|
||||||
o/$(MODE)/tool/net/redbean.o \
|
o/$(MODE)/tool/net/redbean.o \
|
||||||
|
o/$(MODE)/tool/net/lsqlite3.o \
|
||||||
o/$(MODE)/tool/net/net.pkg \
|
o/$(MODE)/tool/net/net.pkg \
|
||||||
$(CRT) \
|
$(CRT) \
|
||||||
$(APE)
|
$(APE)
|
||||||
|
|
|
@ -3646,8 +3646,11 @@ static const luaL_Reg kLuaFuncs[] = {
|
||||||
{"popcnt", LuaPopcnt}, //
|
{"popcnt", LuaPopcnt}, //
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern int luaopen_lsqlite3(lua_State *L);
|
||||||
|
|
||||||
static const luaL_Reg kLuaLibs[] = {
|
static const luaL_Reg kLuaLibs[] = {
|
||||||
{"re", LuaRe}, //
|
{"re", LuaRe}, //
|
||||||
|
{"lsqlite3", luaopen_lsqlite3},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void LuaSetArgv(lua_State *L) {
|
static void LuaSetArgv(lua_State *L) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue