Make and use a vector variant of luax_convobj

Which also prevents accessing the zeroeth element of an empty vector
This commit is contained in:
Bart van Strien
2018-12-03 18:19:28 +01:00
parent a1d6da4624
commit 7253118100
3 changed files with 20 additions and 6 deletions
+14 -2
View File
@@ -623,7 +623,7 @@ int luax_convobj(lua_State *L, int idx, const char *mod, const char *fn)
return 0;
}
int luax_convobj(lua_State *L, int idxs[], int n, const char *mod, const char *fn)
int luax_convobj(lua_State *L, const int idxs[], int n, const char *mod, const char *fn)
{
luax_getfunction(L, mod, fn);
for (int i = 0; i < n; i++)
@@ -638,6 +638,12 @@ int luax_convobj(lua_State *L, int idxs[], int n, const char *mod, const char *f
return 0;
}
int luax_convobj(lua_State *L, const std::vector<int>& idxs, const char *module, const char *function)
{
const int *idxPtr = idxs.size() > 0 ? &idxs[0] : nullptr;
return luax_convobj(L, idxPtr, (int) idxs.size(), module, function);
}
int luax_pconvobj(lua_State *L, int idx, const char *mod, const char *fn)
{
// Convert string to a file.
@@ -649,7 +655,7 @@ int luax_pconvobj(lua_State *L, int idx, const char *mod, const char *fn)
return ret;
}
int luax_pconvobj(lua_State *L, int idxs[], int n, const char *mod, const char *fn)
int luax_pconvobj(lua_State *L, const int idxs[], int n, const char *mod, const char *fn)
{
luax_getfunction(L, mod, fn);
for (int i = 0; i < n; i++)
@@ -662,6 +668,12 @@ int luax_pconvobj(lua_State *L, int idxs[], int n, const char *mod, const char *
return ret;
}
int luax_pconvobj(lua_State *L, const std::vector<int>& idxs, const char *module, const char *function)
{
const int *idxPtr = idxs.size() > 0 ? &idxs[0] : nullptr;
return luax_pconvobj(L, idxPtr, (int) idxs.size(), module, function);
}
int luax_insist(lua_State *L, int idx, const char *k)
{
// Convert to absolute index if necessary.