mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +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. *
|
||||
************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
// attribution in binary form
|
||||
asm(".ident\t\"\\n\\n\
|
||||
lsqlite3 (MIT License)\\n\
|
||||
Copyright 2002-2016 Tiago Dionizio, Doug Currie\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
#define LUA_LIB
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
||||
#include "third_party/lua/lua.h"
|
||||
#include "third_party/lua/lauxlib.h"
|
||||
|
||||
#if LUA_VERSION_NUM > 501
|
||||
/*
|
||||
|
@ -56,7 +60,7 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#include "sqlite3.h"
|
||||
#include "third_party/sqlite3/sqlite3.h"
|
||||
|
||||
/* compile time features */
|
||||
#if !defined(SQLITE_OMIT_PROGRESS_CALLBACK)
|
||||
|
@ -1219,6 +1223,10 @@ static int db_create_collation(lua_State *L) {
|
|||
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...
|
||||
*/
|
||||
static int db_load_extension(lua_State *L) {
|
||||
|
@ -1246,6 +1254,7 @@ static int db_load_extension(lua_State *L) {
|
|||
sqlite3_free(errmsg);
|
||||
return 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** trace callback:
|
||||
|
@ -2238,7 +2247,9 @@ static const luaL_Reg dblib[] = {
|
|||
{"create_function", db_create_function },
|
||||
{"create_aggregate", db_create_aggregate },
|
||||
{"create_collation", db_create_collation },
|
||||
#if 0
|
||||
{"load_extension", db_load_extension },
|
||||
#endif
|
||||
|
||||
{"trace", db_trace },
|
||||
{"progress_handler", db_progress_handler },
|
||||
|
|
|
@ -42,6 +42,7 @@ TOOL_NET_DIRECTDEPS = \
|
|||
NET_HTTP \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_LUA \
|
||||
THIRD_PARTY_SQLITE3 \
|
||||
THIRD_PARTY_REGEX \
|
||||
THIRD_PARTY_ZLIB \
|
||||
TOOL_DECODE_LIB
|
||||
|
@ -51,6 +52,7 @@ TOOL_NET_DEPS := \
|
|||
|
||||
o/$(MODE)/tool/net/net.pkg: \
|
||||
$(TOOL_NET_OBJS) \
|
||||
o/tool/net/lsqlite3.o \
|
||||
$(foreach x,$(TOOL_NET_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/tool/net/%.com.dbg: \
|
||||
|
@ -64,6 +66,7 @@ o/$(MODE)/tool/net/%.com.dbg: \
|
|||
o/$(MODE)/tool/net/redbean.com.dbg: \
|
||||
$(TOOL_NET_DEPS) \
|
||||
o/$(MODE)/tool/net/redbean.o \
|
||||
o/$(MODE)/tool/net/lsqlite3.o \
|
||||
o/$(MODE)/tool/net/net.pkg \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
|
|
|
@ -3646,8 +3646,11 @@ static const luaL_Reg kLuaFuncs[] = {
|
|||
{"popcnt", LuaPopcnt}, //
|
||||
};
|
||||
|
||||
extern int luaopen_lsqlite3(lua_State *L);
|
||||
|
||||
static const luaL_Reg kLuaLibs[] = {
|
||||
{"re", LuaRe}, //
|
||||
{"lsqlite3", luaopen_lsqlite3},
|
||||
};
|
||||
|
||||
static void LuaSetArgv(lua_State *L) {
|
||||
|
|
Loading…
Add table
Reference in a new issue