MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / db_sp

Function db_sp

lua/sp.c:4661–4693  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4659}
4660
4661static 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
4695static int db_error(lua_State *lua)
4696{

Callers

nothing calls this directly

Calls 10

luaL_checkudataFunction · 0.85
lua_isnumberFunction · 0.85
lua_tonumberFunction · 0.85
lua_isstringFunction · 0.85
luaL_errorFunction · 0.85
sqlite3ErrStrFunction · 0.85
load_srcFunction · 0.85
freeFunction · 0.85
luabb_errorFunction · 0.85
lua_pushnilFunction · 0.85

Tested by

no test coverage detected