Ejemplo n.º 1
0
static void CreateImageRGBA(void)
{
  int i, count, width, height;
  unsigned char *pixels;
  lua_Object n, obj = luaL_tablearg(3);
  width = luaL_check_int(1);
  height = luaL_check_int(2);
  count = width * height * 4;
  pixels = (unsigned char *) malloc(count);

  for (i = 0; i < count; i++)
  {
    lua_beginblock();
    lua_pushobject(obj);
    lua_pushnumber(i+1);

    n = lua_gettable();
    if (!lua_isnumber(n)) 
    {
      lua_endblock();
      lua_error("iupCreateImage: incorrect value in argument");
    }
    pixels[i] = (unsigned char)lua_getnumber(n);
    lua_endblock();
  }

  lua_pushusertag(IupImageRGBA(width, height, pixels), iuplua_tag);
  free(pixels);
}
Ejemplo n.º 2
0
static void settag (void)
{
  lua_Object o = luaL_tablearg(1);
  lua_pushobject(o);
  lua_settag((int32)luaL_check_number(2));
  lua_pushobject(o);  /* returns first argument */
}
Ejemplo n.º 3
0
static void next() {
	lua_Object o = luaL_tablearg(1);
	lua_Object r = luaL_nonnullarg(2);
	Node *n = luaH_next(luaA_Address(o), luaA_Address(r));
	if (n) {
		luaA_pushobject(&n->ref);
		luaA_pushobject(&n->val);
	}
}
Ejemplo n.º 4
0
static void cfTreeGetTableId(void)
{
  Ihandle* ih = iuplua_checkihandle(1);
  lua_Object o2 = luaL_tablearg(2);
  int ret = tree_gettableid(ih, o2);
	if(ret == -1)
		lua_pushnil();
	else
		lua_pushnumber(ret);
}
Ejemplo n.º 5
0
static void CreateImage(void)
{
  int i, j;
  lua_Object linha;
  int width, height;
  unsigned char *pixels;
  lua_Object obj = luaL_tablearg(3);
  width = luaL_check_int(1);
  height = luaL_check_int(2);
  pixels = (unsigned char *) malloc(width*height);

  for (i = 1; i <= height; i++) 
  {
    lua_beginblock();
    lua_pushobject(obj);
    lua_pushnumber(i);
    linha = lua_gettable();
    if (!lua_istable(linha)) 
    {
      lua_endblock();
      lua_error("iupCreateImage: incorrect value in argument");
    }

    for (j = 1; j <= width; j++) 
    {
      lua_Object n;
      lua_beginblock();
      lua_pushobject(linha);
      lua_pushnumber(j);
      n = lua_gettable();
      if (!lua_isnumber(n)) 
      {
        lua_endblock();
        lua_error("iupCreateImage: incorrect value in argument");
      }
      pixels[(i - 1) * width + (j - 1)] = (unsigned char) lua_getnumber(n);
      lua_endblock();
    }

    lua_pushobject(obj);
    lua_pushnumber(i);
    lua_pushnil();
    lua_settable();
    lua_endblock();
  }

  lua_pushusertag(IupImage(width, height, pixels), iuplua_tag);
  free(pixels);
}
Ejemplo n.º 6
0
static void foreach (void)
{
  TObject t = *luaA_Address(luaL_tablearg(1));
  TObject f = *luaA_Address(luaL_functionarg(2));
  int32 i;
  for (i=0; i<avalue(&t)->nhash; i++) {
    Node *nd = &(avalue(&t)->node[i]);
    if (ttype(ref(nd)) != LUA_T_NIL && ttype(val(nd)) != LUA_T_NIL) {
      luaA_pushobject(&f);
      luaA_pushobject(ref(nd));
      luaA_pushobject(val(nd));
      luaD_call((L->stack.top-L->stack.stack)-2, 1);
      if (ttype(L->stack.top-1) != LUA_T_NIL)
        return;
      L->stack.top--;
    }
  }
}
Ejemplo n.º 7
0
static void luaI_call (void)
{
  lua_Object f = luaL_nonnullarg(1);
  lua_Object arg = luaL_tablearg(2);
  const char *options = luaL_opt_string(3, "");
  lua_Object err = lua_getparam(4);
  int32 narg = getnarg(arg);
  int32 i, status;
  if (err != LUA_NOOBJECT) {  /* set new error method */
    lua_pushobject(err);
    err = lua_seterrormethod();
  }
  /* push arg[1...n] */
  for (i=0; i<narg; i++) {
    lua_Object temp;
    /* temp = arg[i+1] */
    lua_pushobject(arg); lua_pushnumber(i+1); temp = lua_rawgettable();
    if (narg == MAX_INT && lua_isnil(temp))
      break;
    lua_pushobject(temp);
  }
  status = lua_callfunction(f);
  if (err != LUA_NOOBJECT) {  /* restore old error method */
    lua_pushobject(err);
    lua_seterrormethod();
  }
  if (status != 0) {  /* error in call? */
    if (strchr(options, 'x')) {
      lua_pushnil();
      return;  /* return nil to signal the error */
    }
    else
      lua_error(NULL);
  }
  else { /* no errors */
    if (strchr(options, 'p'))
      luaA_packresults();
    else
      luaA_passresults();
  }
}
Ejemplo n.º 8
0
static void settag() {
	lua_Object o = luaL_tablearg(1);
	lua_pushobject(o);
	lua_settag((int32)luaL_check_number(2));
}
Ejemplo n.º 9
0
static Hash *gethash (int arg) {
  return avalue(luaA_Address(luaL_tablearg(arg)));
}
Ejemplo n.º 10
0
static void luaB_settag (void) {
  lua_Object o = luaL_tablearg(1);
  lua_pushobject(o);
  lua_settag(luaL_check_int(2));
  lua_pushobject(o);  /* return first argument */
}
Ejemplo n.º 11
0
static void ListDialog(void)
{
  lua_Object list_tbl = luaL_tablearg(4);
  lua_Object marks_tbl;
  int i, ret;
  char **list;
  int *marks = NULL;

  int type = luaL_check_int(1);
  char* title = luaL_check_string(2);
  int size = luaL_check_int(3);
  int opt = luaL_check_int(5);
  int max_col = luaL_check_int(6);
  int max_lin = luaL_check_int(7);

  marks_tbl = lua_getparam(8);
  if (!lua_isnil(marks_tbl))
  {
    luaL_arg_check(lua_istable(marks_tbl), 8, "table expected");
    marks = malloc(sizeof(int) * size);
  }

  if (!marks && type==2)
    lua_error("invalid marks, must not be nil.");

  list = malloc(sizeof(char *) * size);

  for (i = 0; i < size; i++) 
  {
    lua_beginblock();

    lua_pushobject(list_tbl);
    lua_pushnumber(i + 1);
    list[i] = lua_getstring(lua_gettable());

    if (marks)
    {
      lua_pushobject(marks_tbl);
      lua_pushnumber(i + 1);
      marks[i] = (int) lua_getnumber(lua_gettable());
    }

    lua_endblock();
  }

  ret = IupListDialog(type, title, size, list, opt, max_col, max_lin, marks);

  if (marks && type==2 && ret!=-1)
  {
    for (i = 0; i < size; i++) 
    {
      lua_beginblock();
      lua_pushobject(marks_tbl);
      lua_pushnumber(i + 1);
      lua_pushnumber(marks[i]);
      lua_settable();
      lua_endblock();
    }
  }

  lua_pushnumber(ret);

  if (marks) free(marks);
  free(list);
}
Ejemplo n.º 12
0
/* Convert a Lua table to a python list */
static void table2list(lua_State *L) {
    python_setnumber(L, PY_LUA_TABLE_CONVERT, 1);
    push_pyobject_container(L, ltable2list(L, luaL_tablearg(L, 1)), true);
    python_setnumber(L, PY_LUA_TABLE_CONVERT, 0);
}