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

Function db_bootstrap

lua/sp.c:4867–4905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4865}
4866
4867static int db_bootstrap(Lua L)
4868{
4869 luaL_checkudata(L, 1, dbtypes.db);
4870 lua_pop(L, 1);
4871
4872 lua_Debug ar = {0};
4873 const int frame = 2; // 0 -> db_bootstrap , 1 -> comdb2_main, 2 -> SP
4874 if (lua_getstack(L, frame, &ar) == 0) return 0;
4875
4876 lua_getglobal(L, "_SP");
4877 lua_newtable(L);
4878 lua_setfield(L, -2, "cdb2_func_refs");
4879 lua_newtable(L);
4880 lua_setfield(L, -2, "cdb2_func_names");
4881
4882 lua_getfield(L, 1, "cdb2_func_refs");
4883 lua_getfield(L, 1, "cdb2_func_names");
4884
4885 // Stack:
4886 // 3: table for lookup by name
4887 // 2: table for lookup by ref
4888 // 1: _SP{}
4889
4890 int n = 1; // 1st local variable
4891 const char *name;
4892 while ((name = lua_getlocal(L, &ar, n++)) != NULL) {
4893 if (!lua_isfunction(L, -1)) {
4894 lua_pop(L, 1);
4895 continue;
4896 }
4897 lua_pushvalue(L, -1); // push copy of func
4898 lua_setfield(L, 3, name); // _SP.cdb2_func_names[funcname] = func
4899 lua_pushstring(L, name);
4900 lua_settable(L, 2); // _SP.cdb2_func_refs[func] = funcname
4901 }
4902 lua_settop(L, 0);
4903
4904 return 0;
4905}
4906
4907static int db_ctrace(Lua L)
4908{

Callers

nothing calls this directly

Calls 9

luaL_checkudataFunction · 0.85
lua_getstackFunction · 0.85
lua_setfieldFunction · 0.85
lua_getfieldFunction · 0.85
lua_getlocalFunction · 0.85
lua_pushvalueFunction · 0.85
lua_pushstringFunction · 0.85
lua_settableFunction · 0.85
lua_settopFunction · 0.85

Tested by

no test coverage detected