]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Lua/src/ldblib.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Lua / src / ldblib.c
diff --git a/AppPkg/Applications/Lua/src/ldblib.c b/AppPkg/Applications/Lua/src/ldblib.c
deleted file mode 100644 (file)
index 5a944b6..0000000
+++ /dev/null
@@ -1,398 +0,0 @@
-/*\r
-** $Id: ldblib.c,v 1.132.1.1 2013/04/12 18:48:47 roberto Exp $\r
-** Interface from Lua to its debug API\r
-** See Copyright Notice in lua.h\r
-*/\r
-\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#define ldblib_c\r
-#define LUA_LIB\r
-\r
-#include "lua.h"\r
-\r
-#include "lauxlib.h"\r
-#include "lualib.h"\r
-\r
-\r
-#define HOOKKEY   "_HKEY"\r
-\r
-\r
-\r
-static int db_getregistry (lua_State *L) {\r
-  lua_pushvalue(L, LUA_REGISTRYINDEX);\r
-  return 1;\r
-}\r
-\r
-\r
-static int db_getmetatable (lua_State *L) {\r
-  luaL_checkany(L, 1);\r
-  if (!lua_getmetatable(L, 1)) {\r
-    lua_pushnil(L);  /* no metatable */\r
-  }\r
-  return 1;\r
-}\r
-\r
-\r
-static int db_setmetatable (lua_State *L) {\r
-  int t = lua_type(L, 2);\r
-  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\r
-                    "nil or table expected");\r
-  lua_settop(L, 2);\r
-  lua_setmetatable(L, 1);\r
-  return 1;  /* return 1st argument */\r
-}\r
-\r
-\r
-static int db_getuservalue (lua_State *L) {\r
-  if (lua_type(L, 1) != LUA_TUSERDATA)\r
-    lua_pushnil(L);\r
-  else\r
-    lua_getuservalue(L, 1);\r
-  return 1;\r
-}\r
-\r
-\r
-static int db_setuservalue (lua_State *L) {\r
-  if (lua_type(L, 1) == LUA_TLIGHTUSERDATA)\r
-    luaL_argerror(L, 1, "full userdata expected, got light userdata");\r
-  luaL_checktype(L, 1, LUA_TUSERDATA);\r
-  if (!lua_isnoneornil(L, 2))\r
-    luaL_checktype(L, 2, LUA_TTABLE);\r
-  lua_settop(L, 2);\r
-  lua_setuservalue(L, 1);\r
-  return 1;\r
-}\r
-\r
-\r
-static void settabss (lua_State *L, const char *i, const char *v) {\r
-  lua_pushstring(L, v);\r
-  lua_setfield(L, -2, i);\r
-}\r
-\r
-\r
-static void settabsi (lua_State *L, const char *i, int v) {\r
-  lua_pushinteger(L, v);\r
-  lua_setfield(L, -2, i);\r
-}\r
-\r
-\r
-static void settabsb (lua_State *L, const char *i, int v) {\r
-  lua_pushboolean(L, v);\r
-  lua_setfield(L, -2, i);\r
-}\r
-\r
-\r
-static lua_State *getthread (lua_State *L, int *arg) {\r
-  if (lua_isthread(L, 1)) {\r
-    *arg = 1;\r
-    return lua_tothread(L, 1);\r
-  }\r
-  else {\r
-    *arg = 0;\r
-    return L;\r
-  }\r
-}\r
-\r
-\r
-static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {\r
-  if (L == L1) {\r
-    lua_pushvalue(L, -2);\r
-    lua_remove(L, -3);\r
-  }\r
-  else\r
-    lua_xmove(L1, L, 1);\r
-  lua_setfield(L, -2, fname);\r
-}\r
-\r
-\r
-static int db_getinfo (lua_State *L) {\r
-  lua_Debug ar;\r
-  int arg;\r
-  lua_State *L1 = getthread(L, &arg);\r
-  const char *options = luaL_optstring(L, arg+2, "flnStu");\r
-  if (lua_isnumber(L, arg+1)) {\r
-    if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {\r
-      lua_pushnil(L);  /* level out of range */\r
-      return 1;\r
-    }\r
-  }\r
-  else if (lua_isfunction(L, arg+1)) {\r
-    lua_pushfstring(L, ">%s", options);\r
-    options = lua_tostring(L, -1);\r
-    lua_pushvalue(L, arg+1);\r
-    lua_xmove(L, L1, 1);\r
-  }\r
-  else\r
-    return luaL_argerror(L, arg+1, "function or level expected");\r
-  if (!lua_getinfo(L1, options, &ar))\r
-    return luaL_argerror(L, arg+2, "invalid option");\r
-  lua_createtable(L, 0, 2);\r
-  if (strchr(options, 'S')) {\r
-    settabss(L, "source", ar.source);\r
-    settabss(L, "short_src", ar.short_src);\r
-    settabsi(L, "linedefined", ar.linedefined);\r
-    settabsi(L, "lastlinedefined", ar.lastlinedefined);\r
-    settabss(L, "what", ar.what);\r
-  }\r
-  if (strchr(options, 'l'))\r
-    settabsi(L, "currentline", ar.currentline);\r
-  if (strchr(options, 'u')) {\r
-    settabsi(L, "nups", ar.nups);\r
-    settabsi(L, "nparams", ar.nparams);\r
-    settabsb(L, "isvararg", ar.isvararg);\r
-  }\r
-  if (strchr(options, 'n')) {\r
-    settabss(L, "name", ar.name);\r
-    settabss(L, "namewhat", ar.namewhat);\r
-  }\r
-  if (strchr(options, 't'))\r
-    settabsb(L, "istailcall", ar.istailcall);\r
-  if (strchr(options, 'L'))\r
-    treatstackoption(L, L1, "activelines");\r
-  if (strchr(options, 'f'))\r
-    treatstackoption(L, L1, "func");\r
-  return 1;  /* return table */\r
-}\r
-\r
-\r
-static int db_getlocal (lua_State *L) {\r
-  int arg;\r
-  lua_State *L1 = getthread(L, &arg);\r
-  lua_Debug ar;\r
-  const char *name;\r
-  int nvar = luaL_checkint(L, arg+2);  /* local-variable index */\r
-  if (lua_isfunction(L, arg + 1)) {  /* function argument? */\r
-    lua_pushvalue(L, arg + 1);  /* push function */\r
-    lua_pushstring(L, lua_getlocal(L, NULL, nvar));  /* push local name */\r
-    return 1;\r
-  }\r
-  else {  /* stack-level argument */\r
-    if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar))  /* out of range? */\r
-      return luaL_argerror(L, arg+1, "level out of range");\r
-    name = lua_getlocal(L1, &ar, nvar);\r
-    if (name) {\r
-      lua_xmove(L1, L, 1);  /* push local value */\r
-      lua_pushstring(L, name);  /* push name */\r
-      lua_pushvalue(L, -2);  /* re-order */\r
-      return 2;\r
-    }\r
-    else {\r
-      lua_pushnil(L);  /* no name (nor value) */\r
-      return 1;\r
-    }\r
-  }\r
-}\r
-\r
-\r
-static int db_setlocal (lua_State *L) {\r
-  int arg;\r
-  lua_State *L1 = getthread(L, &arg);\r
-  lua_Debug ar;\r
-  if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar))  /* out of range? */\r
-    return luaL_argerror(L, arg+1, "level out of range");\r
-  luaL_checkany(L, arg+3);\r
-  lua_settop(L, arg+3);\r
-  lua_xmove(L, L1, 1);\r
-  lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));\r
-  return 1;\r
-}\r
-\r
-\r
-static int auxupvalue (lua_State *L, int get) {\r
-  const char *name;\r
-  int n = luaL_checkint(L, 2);\r
-  luaL_checktype(L, 1, LUA_TFUNCTION);\r
-  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\r
-  if (name == NULL) return 0;\r
-  lua_pushstring(L, name);\r
-  lua_insert(L, -(get+1));\r
-  return get + 1;\r
-}\r
-\r
-\r
-static int db_getupvalue (lua_State *L) {\r
-  return auxupvalue(L, 1);\r
-}\r
-\r
-\r
-static int db_setupvalue (lua_State *L) {\r
-  luaL_checkany(L, 3);\r
-  return auxupvalue(L, 0);\r
-}\r
-\r
-\r
-static int checkupval (lua_State *L, int argf, int argnup) {\r
-  lua_Debug ar;\r
-  int nup = luaL_checkint(L, argnup);\r
-  luaL_checktype(L, argf, LUA_TFUNCTION);\r
-  lua_pushvalue(L, argf);\r
-  lua_getinfo(L, ">u", &ar);\r
-  luaL_argcheck(L, 1 <= nup && nup <= ar.nups, argnup, "invalid upvalue index");\r
-  return nup;\r
-}\r
-\r
-\r
-static int db_upvalueid (lua_State *L) {\r
-  int n = checkupval(L, 1, 2);\r
-  lua_pushlightuserdata(L, lua_upvalueid(L, 1, n));\r
-  return 1;\r
-}\r
-\r
-\r
-static int db_upvaluejoin (lua_State *L) {\r
-  int n1 = checkupval(L, 1, 2);\r
-  int n2 = checkupval(L, 3, 4);\r
-  luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected");\r
-  luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected");\r
-  lua_upvaluejoin(L, 1, n1, 3, n2);\r
-  return 0;\r
-}\r
-\r
-\r
-#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)\r
-\r
-\r
-static void hookf (lua_State *L, lua_Debug *ar) {\r
-  static const char *const hooknames[] =\r
-    {"call", "return", "line", "count", "tail call"};\r
-  gethooktable(L);\r
-  lua_pushthread(L);\r
-  lua_rawget(L, -2);\r
-  if (lua_isfunction(L, -1)) {\r
-    lua_pushstring(L, hooknames[(int)ar->event]);\r
-    if (ar->currentline >= 0)\r
-      lua_pushinteger(L, ar->currentline);\r
-    else lua_pushnil(L);\r
-    lua_assert(lua_getinfo(L, "lS", ar));\r
-    lua_call(L, 2, 0);\r
-  }\r
-}\r
-\r
-\r
-static int makemask (const char *smask, int count) {\r
-  int mask = 0;\r
-  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\r
-  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\r
-  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\r
-  if (count > 0) mask |= LUA_MASKCOUNT;\r
-  return mask;\r
-}\r
-\r
-\r
-static char *unmakemask (int mask, char *smask) {\r
-  int i = 0;\r
-  if (mask & LUA_MASKCALL) smask[i++] = 'c';\r
-  if (mask & LUA_MASKRET) smask[i++] = 'r';\r
-  if (mask & LUA_MASKLINE) smask[i++] = 'l';\r
-  smask[i] = '\0';\r
-  return smask;\r
-}\r
-\r
-\r
-static int db_sethook (lua_State *L) {\r
-  int arg, mask, count;\r
-  lua_Hook func;\r
-  lua_State *L1 = getthread(L, &arg);\r
-  if (lua_isnoneornil(L, arg+1)) {\r
-    lua_settop(L, arg+1);\r
-    func = NULL; mask = 0; count = 0;  /* turn off hooks */\r
-  }\r
-  else {\r
-    const char *smask = luaL_checkstring(L, arg+2);\r
-    luaL_checktype(L, arg+1, LUA_TFUNCTION);\r
-    count = luaL_optint(L, arg+3, 0);\r
-    func = hookf; mask = makemask(smask, count);\r
-  }\r
-  if (gethooktable(L) == 0) {  /* creating hook table? */\r
-    lua_pushstring(L, "k");\r
-    lua_setfield(L, -2, "__mode");  /** hooktable.__mode = "k" */\r
-    lua_pushvalue(L, -1);\r
-    lua_setmetatable(L, -2);  /* setmetatable(hooktable) = hooktable */\r
-  }\r
-  lua_pushthread(L1); lua_xmove(L1, L, 1);\r
-  lua_pushvalue(L, arg+1);\r
-  lua_rawset(L, -3);  /* set new hook */\r
-  lua_sethook(L1, func, mask, count);  /* set hooks */\r
-  return 0;\r
-}\r
-\r
-\r
-static int db_gethook (lua_State *L) {\r
-  int arg;\r
-  lua_State *L1 = getthread(L, &arg);\r
-  char buff[5];\r
-  int mask = lua_gethookmask(L1);\r
-  lua_Hook hook = lua_gethook(L1);\r
-  if (hook != NULL && hook != hookf)  /* external hook? */\r
-    lua_pushliteral(L, "external hook");\r
-  else {\r
-    gethooktable(L);\r
-    lua_pushthread(L1); lua_xmove(L1, L, 1);\r
-    lua_rawget(L, -2);   /* get hook */\r
-    lua_remove(L, -2);  /* remove hook table */\r
-  }\r
-  lua_pushstring(L, unmakemask(mask, buff));\r
-  lua_pushinteger(L, lua_gethookcount(L1));\r
-  return 3;\r
-}\r
-\r
-\r
-static int db_debug (lua_State *L) {\r
-  for (;;) {\r
-    char buffer[250];\r
-    luai_writestringerror("%s", "lua_debug> ");\r
-    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\r
-        strcmp(buffer, "cont\n") == 0)\r
-      return 0;\r
-    if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||\r
-        lua_pcall(L, 0, 0, 0))\r
-      luai_writestringerror("%s\n", lua_tostring(L, -1));\r
-    lua_settop(L, 0);  /* remove eventual returns */\r
-  }\r
-}\r
-\r
-\r
-static int db_traceback (lua_State *L) {\r
-  int arg;\r
-  lua_State *L1 = getthread(L, &arg);\r
-  const char *msg = lua_tostring(L, arg + 1);\r
-  if (msg == NULL && !lua_isnoneornil(L, arg + 1))  /* non-string 'msg'? */\r
-    lua_pushvalue(L, arg + 1);  /* return it untouched */\r
-  else {\r
-    int level = luaL_optint(L, arg + 2, (L == L1) ? 1 : 0);\r
-    luaL_traceback(L, L1, msg, level);\r
-  }\r
-  return 1;\r
-}\r
-\r
-\r
-static const luaL_Reg dblib[] = {\r
-  {"debug", db_debug},\r
-  {"getuservalue", db_getuservalue},\r
-  {"gethook", db_gethook},\r
-  {"getinfo", db_getinfo},\r
-  {"getlocal", db_getlocal},\r
-  {"getregistry", db_getregistry},\r
-  {"getmetatable", db_getmetatable},\r
-  {"getupvalue", db_getupvalue},\r
-  {"upvaluejoin", db_upvaluejoin},\r
-  {"upvalueid", db_upvalueid},\r
-  {"setuservalue", db_setuservalue},\r
-  {"sethook", db_sethook},\r
-  {"setlocal", db_setlocal},\r
-  {"setmetatable", db_setmetatable},\r
-  {"setupvalue", db_setupvalue},\r
-  {"traceback", db_traceback},\r
-  {NULL, NULL}\r
-};\r
-\r
-\r
-LUAMOD_API int luaopen_debug (lua_State *L) {\r
-  luaL_newlib(L, dblib);\r
-  return 1;\r
-}\r
-\r