Skip to content

Commit

Permalink
Solved issue #125. Updated function to throw errors in case of not ta…
Browse files Browse the repository at this point in the history
…ble given.
  • Loading branch information
pakozm committed Feb 14, 2015
1 parent 00dc888 commit 685edc9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
41 changes: 0 additions & 41 deletions binding/c_src/utilLua.cc
@@ -1,46 +1,5 @@
#include "utilLua.h"

//devuelve true si consigue leer "name" en la tabla que esté en el top
// y en v[] deja los n primeros valores
bool leer_int_params(lua_State *L, const char *name, int *v, int n) {
// table
lua_pushstring(L, name); // name (atributo)
lua_gettable(L,-2);
if (!lua_istable(L,-1)) {
lua_pop(L,1); //remove string
return false;
}
// tabla del atributo
for (int i = 1; i <= n; i++) {
lua_rawgeti(L, -1, i);
v[i-1] = (int)luaL_checknumber(L, -1);
lua_pop(L,1);
}
lua_pop(L,1); //tabla del atributo

return true;
}

//idem pero leyendo bool's
bool leer_bool_params(lua_State *L, const char *name, bool *v, int n) {
// table
lua_pushstring(L, name); // name (atributo)
lua_gettable(L,-2);
if (!lua_istable(L,-1)) {
lua_pop(L,1); //remove string
return false;
}
// tabla del atributo
for (int i = 1; i <= n; i++) {
lua_rawgeti(L, -1, i);
v[i-1] = (lua_toboolean(L, -1) != 0);
lua_pop(L,1);
}
lua_pop(L,1); //tabla del atributo

return true;
}

int table_to_char_vector(lua_State *L, char ***vec) {
int length = table_getn(L);
char **v = new char*[length];
Expand Down
48 changes: 48 additions & 0 deletions packages/basics/dataset/binding/bind_dataset.lua.cc
Expand Up @@ -25,13 +25,61 @@
#include "bind_mtrand.h"
#include "bind_referenced_vector.h"
#include "bind_tokens.h"
#include "error_print.h"
#include "fmeasure.h"
#include "matrix_operations.h"
#include "MersenneTwister.h"

using AprilUtils::constString;
using namespace AprilMath::MatrixExt::Operations;

//devuelve true si consigue leer "name" en la tabla que esté en el top
// y en v[] deja los n primeros valores
bool leer_int_params(lua_State *L, const char *name, int *v, int n) {
// table
lua_pushstring(L, name); // name (atributo)
lua_gettable(L,-2);
if (lua_isnil(L,-1)) {
lua_pop(L,1); //remove string
return false;
}
else if (!lua_istable(L,-1)) {
ERROR_EXIT1(128, "Expected a table in field %s\n", name);
}
// tabla del atributo
for (int i = 1; i <= n; i++) {
lua_rawgeti(L, -1, i);
v[i-1] = (int)luaL_checknumber(L, -1);
lua_pop(L,1);
}
lua_pop(L,1); //tabla del atributo

return true;
}

//idem pero leyendo bool's
bool leer_bool_params(lua_State *L, const char *name, bool *v, int n) {
// table
lua_pushstring(L, name); // name (atributo)
lua_gettable(L,-2);
if (lua_isnil(L,-1)) {
lua_pop(L,1); //remove string
return false;
}
else if (!lua_istable(L,-1)) {
ERROR_EXIT1(128, "Expected a table in field %s\n", name);
}
// tabla del atributo
for (int i = 1; i <= n; i++) {
lua_rawgeti(L, -1, i);
v[i-1] = (lua_toboolean(L, -1) != 0);
lua_pop(L,1);
}
lua_pop(L,1); //tabla del atributo

return true;
}

namespace Basics {

int dataset_iterator_function(lua_State *L) {
Expand Down

0 comments on commit 685edc9

Please sign in to comment.