| 4659 | } |
| 4660 | |
| 4661 | static int db_sp(Lua L) |
| 4662 | { |
| 4663 | luaL_checkudata(L, 1, dbtypes.db); |
| 4664 | char *name = (char *)luaL_checkstring(L, 2); |
| 4665 | struct spversion_t spversion = {0}; |
| 4666 | if (lua_isnumber(L, 3)) { |
| 4667 | spversion.version_num = lua_tonumber(L, 3); |
| 4668 | } else if (lua_isstring(L, 3)) { |
| 4669 | spversion.version_str = (char *)lua_tostring(L, 3); |
| 4670 | } |
| 4671 | char *err = NULL; |
| 4672 | if (tryrdlock_schema_lk() != 0) { |
| 4673 | return luaL_error(L, sqlite3ErrStr(SQLITE_SCHEMA)); |
| 4674 | } |
| 4675 | char *src = load_src(name, &spversion, 0, &err); |
| 4676 | unlock_schema_lk(); |
| 4677 | free(spversion.version_str); |
| 4678 | if (src == NULL) { |
| 4679 | luabb_error(L, getsp(L), err); |
| 4680 | lua_pushnil(L); |
| 4681 | free(err); |
| 4682 | return 1; |
| 4683 | } |
| 4684 | size_t size = strlen(src); |
| 4685 | char buf[size + 32]; |
| 4686 | sprintf(buf, "%s\nreturn main", src); |
| 4687 | free(src); |
| 4688 | if (luaL_dostring(L, buf) != 0) { |
| 4689 | luabb_error(L, getsp(L), lua_tostring(L, -1)); |
| 4690 | lua_pushnil(L); |
| 4691 | } |
| 4692 | return 1; |
| 4693 | } |
| 4694 | |
| 4695 | static int db_error(lua_State *lua) |
| 4696 | { |
nothing calls this directly
no test coverage detected