Exemplo n.º 1
0
void L1_typeOverride() {
	lua_Object data = lua_getparam(1);

	if (lua_isuserdata(data)) {
		switch (lua_tag(data)) {
		case MKTAG('A','C','T','R'):
			lua_pushstring("actor");
			lua_pushnumber(lua_tag(data));
			return;
		case MKTAG('C','O','S','T'):
			lua_pushstring("costume");
			lua_pushnumber(lua_tag(data));
			return;
		case MKTAG('S','E','T',' '):
			lua_pushstring("set");
			lua_pushnumber(lua_tag(data));
			return;
		case MKTAG('K','E','Y','F'):
			lua_pushstring("keyframe");
			lua_pushnumber(lua_tag(data));
			return;
		default:
			break;
		}
	}

	lua_pushobject(data);
	lua_callfunction(lua_getref(refTypeOverride));
	lua_Object param1 = lua_getresult(1);
	lua_Object param2 = lua_getresult(2);
	lua_pushobject(param1);
	lua_pushobject(param2);
}
Exemplo n.º 2
0
/***************************************************************************\
* CGM CD_SCLMDE.                                                            *
\***************************************************************************/
static int cgm_sclmdecb(cdCanvas *canvas, short scl_mde, short *draw_mode_i, double *factor_f)
{
    lua_Object func, result, draw_mode, factor;
    int result_i;

    lua_beginblock();
    func = lua_getref(cdluacgmcb[CD_CGMSCLMDECB].lock);

    cdlua_pushcanvas(canvas);
    lua_pushnumber( scl_mde);
    lua_callfunction(func);

    result = lua_getresult(1);
    if (!lua_isnumber(result))
        lua_error("cdPlay: CD_CGMSCLMDECB: invalid return value!");
    result_i = (int) lua_getnumber(result);
    if (result_i == 1) {
        lua_endblock();
        return 1;
    }

    draw_mode = lua_getresult(2);
    if (!lua_isnumber(draw_mode))
        lua_error("cdPlay: CD_CGMSCLMDECB: invalid draw_mode return value!");
    *draw_mode_i = (short) lua_getnumber(draw_mode);

    factor = lua_getresult(3);
    if (!lua_isnumber(factor))
        lua_error("cdPlay: CD_CGMSCLMDECB: invalid factor return value!");
    *factor_f = (double) lua_getnumber(factor);

    lua_endblock();

    return result_i;
}
Exemplo n.º 3
0
/***************************************************************************\
* CGM CD_VDCEXTCB.                                                          *
\***************************************************************************/
static int cgm_vdcextcb(cdCanvas *canvas, short type, void *xmn, void *ymn, void *xmx, void *ymx)
{
    lua_Object func, result, xmn_l, ymn_l, xmx_l, ymx_l;
    int result_i;

    lua_beginblock();
    func = lua_getref(cdluacgmcb[CD_CGMVDCEXTCB].lock);

    cdlua_pushcanvas(canvas);
    lua_callfunction(func);

    result = lua_getresult(1);
    if (!lua_isnumber(result))
        lua_error("cdPlay: CD_CGMVDCEXTCB: invalid return value!");
    result_i = (int) lua_getnumber(result);
    if (result_i == 1) {
        lua_endblock();
        return 1;
    }

    xmn_l = lua_getresult(2);
    if (!lua_isnumber(xmn_l))
        lua_error("cdPlay: CD_CGMVDCEXTCB: invalid xmn return value!");
    if (type == 1) *((float *) xmn) = (float) lua_getnumber(xmn_l);
    else *((int *) xmn) = (int) lua_getnumber(xmn_l);

    ymn_l = lua_getresult(3);
    if (!lua_isnumber(ymn_l))
        lua_error("cdPlay: CD_CGMVDCEXTCB: invalid ymn return value!");
    if (type == 1) *((float *) ymn) = (float) lua_getnumber(ymn_l);
    else *((int *) ymn) = (int) lua_getnumber(ymn_l);

    xmx_l = lua_getresult(4);
    if (!lua_isnumber(xmx_l))
        lua_error("cdPlay: CD_CGMVDCEXTCB: invalid xmx return value!");
    if (type == 1) *((float *) xmx) = (float) lua_getnumber(xmx_l);
    else *((int *) xmx) = (int) lua_getnumber(xmx_l);

    ymx_l = lua_getresult(5);
    if (!lua_isnumber(ymx_l))
        lua_error("cdPlay: CD_CGMVDCEXTCB: invalid ymx return value!");
    if (type == 1) *((float *) ymx) = (float) lua_getnumber(ymx_l);
    else *((int *) ymx) = (int) lua_getnumber(ymx_l);

    lua_endblock();

    return result_i;
}
Exemplo n.º 4
0
int iuplua_call(void)
{
  lua_Object obj;

  if (lua_call("iupCallMethod")) 
  {
    lua_endblock();
    return IUP_DEFAULT;  /* call failed */
  }

  obj = lua_getresult(1);
  if (obj == LUA_NOOBJECT) 
  {
    lua_endblock();
    return IUP_DEFAULT; /* no return, provides IUP_DEFAULT return */
  } 
  else if (lua_isnumber(obj)) 
  {
    int ret = (int) lua_getnumber(obj);
    lua_endblock();
    return ret;
  }
  lua_endblock();
  return IUP_DEFAULT; /* returned a non normal value. what to do? */
}
Exemplo n.º 5
0
static void iuplua_settable(void)
{
  lua_Object t, index, value, tab, result;
  t = lua_getparam(1);
  index = lua_getparam(2);
  value = lua_getparam(3);
  lua_pushobject(lua_getglobal("iup_handles"));
  lua_pushobject(t);
  tab = lua_gettable();
  if (lua_isnil(tab)) 
  {
    lua_pushnil();
    return;
  } 
  else 
  {
    lua_Object method;
    lua_pushobject(tab);
    lua_pushstring("set");
    method = lua_gettable();
    lua_pushobject(tab);
    lua_pushobject(index);
    lua_pushobject(value);
    if (lua_callfunction(method))
      return;
  }

  result = lua_getresult(1);
  if (result != LUA_NOOBJECT)
    lua_pushobject(result);
}
Exemplo n.º 6
0
char* iuplua_call_rs(void)
{
  lua_Object obj;

  if (lua_call("iupCallMethod")) 
  {
    lua_endblock();
    return NULL;  /* call failed */
  }

  obj = lua_getresult(1);
  if (obj == LUA_NOOBJECT) 
  {
    lua_endblock();
    return NULL; /* no return, provides IUP_DEFAULT return */
  } 
  else if (lua_isstring(obj)) 
  {
    char* ret = lua_getstring(obj);
    lua_endblock();
    return ret;
  }
  lua_endblock();
  return NULL; /* returned a non normal value. what to do? */
}
Exemplo n.º 7
0
static int pplot_edit_cb(Ihandle *self, int p0, int p1, float p2, float p3, float *p4, float *p5)
{
  lua_Object obj;
  iuplua_call_start(self, "edit_cb");
  lua_pushnumber(p0);
  lua_pushnumber(p1);
  lua_pushnumber(p2);
  lua_pushnumber(p3);
  if (lua_call ("iupCallMethod"))
  {
    lua_endblock ();
    return IUP_IGNORE;
  }
  obj = lua_getresult (1);
  if (obj == LUA_NOOBJECT)
  {
    lua_endblock ();
    return IUP_IGNORE;
  }
  else if (lua_isnumber (obj))
  {
    int ret;
    *p4 = (float)lua_getnumber (obj);

    obj = lua_getresult (2);
    if (obj == LUA_NOOBJECT || !lua_isnumber (obj))
    {
      lua_endblock ();
      return IUP_IGNORE;
    }
    *p5 = (float)lua_getnumber (obj);

    obj = lua_getresult (4);
    if (obj == LUA_NOOBJECT || !lua_isnumber (obj))
    {
      lua_endblock ();
      return IUP_DEFAULT;
    }
    ret = (int)lua_getnumber (obj);
    lua_endblock ();
    return ret;
  }

  lua_endblock ();
  return IUP_IGNORE;
}
Exemplo n.º 8
0
static int cgm_begmtfcb(cdCanvas *canvas, int *xmn, int *ymn, int *xmx, int *ymx)
{
    lua_Object func, result, xmn_l, ymn_l, xmx_l, ymx_l;
    int result_i;

    lua_beginblock();
    func = lua_getref(cdluacgmcb[CD_CGMBEGMTFCB].lock);

    cdlua_pushcanvas(canvas);
    lua_callfunction(func);

    result = lua_getresult(1);
    if (!lua_isnumber(result))
        lua_error("cdPlay: CD_CGMBEGMTFCB: invalid return value!");
    result_i = (int) lua_getnumber(result);
    if (result_i == 1) {
        lua_endblock();
        return 1;
    }

    xmn_l = lua_getresult(2);
    if (!lua_isnumber(xmn_l))
        lua_error("cdPlay: CD_CGMBEGMTFCB: invalid xmn return value!");
    *xmn = (int) lua_getnumber(xmn_l);

    ymn_l = lua_getresult(3);
    if (!lua_isnumber(ymn_l))
        lua_error("cdPlay: CD_CGMBEGMTFCB: invalid ymn return value!");
    *ymn = (int) lua_getnumber(ymn_l);

    xmx_l = lua_getresult(4);
    if (!lua_isnumber(xmx_l))
        lua_error("cdPlay: CD_CGMBEGMTFCB: invalid xmx return value!");
    *xmx = (int) lua_getnumber(xmx_l);

    ymx_l = lua_getresult(5);
    if (!lua_isnumber(ymx_l))
        lua_error("cdPlay: CD_CGMBEGMTFCB: invalid ymx return value!");
    *ymx = (int) lua_getnumber(ymx_l);

    lua_endblock();

    return result_i;
}
Exemplo n.º 9
0
void L1_concatFallback() {
	lua_Object params[2];
	char result[200];
	char *strPtr;

	params[0] = lua_getparam(1);
	params[1] = lua_getparam(2);
	result[0] = 0;

	for (int i = 0; i < 2; i++) {
		if (!lua_isnil(params[i]) && !lua_isuserdata(params[i]) && !lua_isstring(params[i])) {
			lua_pushobject(params[0]);
			lua_pushobject(params[1]);
			lua_callfunction(lua_getref(refOldConcatFallback));
			lua_pushobject(lua_getresult(1));
			return;
		}

		int pos = strlen(result);
		strPtr = &result[pos];

		if (lua_isnil(params[i]))
			sprintf(strPtr, "(nil)");
		else if (lua_isstring(params[i]))
			sprintf(strPtr, "%s", lua_getstring(params[i]));
		else if (lua_tag(params[i]) == MKTAG('A','C','T','R')) {
			Actor *a = getactor(params[i]);
			sprintf(strPtr, "(actor%p:%s)", (void *)a,
				(a->getCurrentCostume() && a->getCurrentCostume()->getModelNodes()) ?
				a->getCurrentCostume()->getModelNodes()->_name : "");
		} else {
			lua_pushobject(params[0]);
			lua_pushobject(params[1]);
			lua_callfunction(lua_getref(refOldConcatFallback));
			lua_pushobject(lua_getresult(1));
			return;
		}
	}

	lua_pushstring(result);
}
Exemplo n.º 10
0
void iuplua_pushihandle(Ihandle *h)
{
  if (h)
  {
    lua_pushusertag((void*)h, iuplua_tag);
    lua_pushstring(IupGetClassName(h));
    lua_call("IupRegisterHandle");
    lua_pushobject(lua_getresult(1));
  }
  else
    lua_pushnil();
}
Exemplo n.º 11
0
/***************************************************************************\
* CGM CD_BEGPICTBCB.                                                         *
\***************************************************************************/
static int cgm_begpictbcb(cdCanvas *canvas)
{
    lua_Object func, result;
    int result_i;

    lua_beginblock();
    func = lua_getref(cdluacgmcb[CD_CGMBEGPICTBCB].lock);

    cdlua_pushcanvas(canvas);
    lua_callfunction(func);

    result = lua_getresult(1);
    if (!lua_isnumber(result))
        lua_error("cdPlay: CD_CGMBEGPICTBCB: invalid return value!");
    result_i = (int) lua_getnumber(result);

    lua_endblock();

    return result_i;
}
Exemplo n.º 12
0
static void add_s (lua_Object newp, struct Capture *cap)
{
  if (lua_isstring(newp)) {
    const char *news = lua_getstring(newp);
    int32 l = lua_strlen(newp);
    int32 i;
    for (i=0; i<l; i++) {
      if (news[i] != ESC)
        luaL_addchar(news[i]);
      else {
        i++;  /* skip ESC */
        if (!isdigit((byte)news[i]))
          luaL_addchar(news[i]);
        else {
          int32 level = check_cap(news[i], cap);
          addnchar(cap->capture[level].init, cap->capture[level].len);
        }
      }
    }
  }
  else {  /* is a function */
    lua_Object res;
    int32 status;
    int32 oldbuff;
    lua_beginblock();
    push_captures(cap);
    /* function may use buffer, so save it and create a new one */
    oldbuff = luaL_newbuffer(0);
    status = lua_callfunction(newp);
    /* restore old buffer */
    luaL_oldbuffer(oldbuff);
    if (status != 0) {
      lua_endblock();
      lua_error(NULL);
    }
    res = lua_getresult(1);
    if (lua_isstring(res))
      addnchar(lua_getstring(res), lua_strlen(res));
    lua_endblock();
  }
}
Exemplo n.º 13
0
static int default_idle(void)
{
  lua_Object obj;
  lua_beginblock();
  obj = lua_getref(idle_ref);
  if (lua_callfunction(obj)) 
  {
    lua_endblock();
    return IUP_IGNORE;
  }

  obj = lua_getresult(1);
  if (lua_isnumber(obj)) 
  {
    int ret = (int) lua_getnumber(obj);
    lua_endblock();
    return ret;
  }
  lua_endblock();
  return IUP_DEFAULT;
}
Exemplo n.º 14
0
static void luaB_print (void) {
  lua_Object args[MAXPRINT];
  lua_Object obj;
  int n = 0;
  int i;
  while ((obj = lua_getparam(n+1)) != LUA_NOOBJECT) {
    luaL_arg_check(n < MAXPRINT, n+1, "too many arguments");
    args[n++] = obj;
  }
  for (i=0; i<n; i++) {
    lua_pushobject(args[i]);
    if (lua_call("tostring"))
      lua_error("error in `tostring' called by `print'");
    obj = lua_getresult(1);
    if (!lua_isstring(obj))
      lua_error("`tostring' must return a string to `print'");
    if (i>0) fputs("\t", stdout);
    fputs(lua_getstring(obj), stdout);
  }
  fputs("\n", stdout);
}
Exemplo n.º 15
0
/***************************************************************************\
* CGM CD_COUNTERCB.                                                         *
\***************************************************************************/
static int cgm_countercb(cdCanvas *canvas, double percent)
{
    lua_Object func, result;
    int result_i;

    lua_beginblock();
    func = lua_getref(cdluacgmcb[CD_CGMCOUNTERCB].lock);

    cdlua_pushcanvas(canvas);
    lua_pushnumber( percent);
    lua_callfunction(func);

    result = lua_getresult(1);
    if (!lua_isnumber(result))
        lua_error("cdPlay: CD_CGMCOUNTERCB: invalid return value!");
    result_i = (int) lua_getnumber(result);

    lua_endblock();

    return result_i;
}
Exemplo n.º 16
0
static void add_s (lua_Object newp, lua_Object table, int n)
{
  if (lua_isstring(newp)) {
    char *news = lua_getstring(newp);
    while (*news) {
      if (*news != ESC || !isdigit((unsigned char)*++news))
        luaI_addchar(*news++);
      else {
        int l = check_cap(*news++, num_captures);
        addnchar(capture[l].init, capture[l].len);
      }
    }
  }
  else if (lua_isfunction(newp)) {
    lua_Object res;
    struct lbuff oldbuff;
    int status;
    lua_beginblock();
    if (lua_istable(table)) {
      lua_pushobject(table);
      lua_pushnumber(n);
    }
    push_captures();
    /* function may use lbuffer, so save it and create a new one */
    oldbuff = lbuffer;
    lbuffer.b = NULL; lbuffer.max = lbuffer.size = 0;
    status = lua_callfunction(newp);
    /* restore old buffer */
    free(lbuffer.b);
    lbuffer = oldbuff;
    if (status != 0)
      lua_error(NULL);
    res = lua_getresult(1);
    addstr(lua_isstring(res) ? lua_getstring(res) : "");
    lua_endblock();
  }
  else luaL_arg_check(0, 3, NULL);
}
Exemplo n.º 17
0
/***************************************************************************\
* CLIPBOARD CD_SIZECB.                                                      *
\***************************************************************************/
static int clipboard_sizecb(cdCanvas *canvas, int w, int h, double mm_w, double mm_h)
{
    lua_Object func, result;
    int result_i;

    lua_beginblock();
    func = lua_getref(cdluaclipboardcb[CD_SIZECB].lock);

    cdlua_pushcanvas(canvas);
    lua_pushnumber( w);
    lua_pushnumber( h);
    lua_pushnumber( mm_w);
    lua_pushnumber( mm_h);
    lua_callfunction(func);

    result = lua_getresult(1);
    if (!lua_isnumber(result))
        lua_error("cdPlay: CD_SIZECB: invalid return value!");
    result_i = (int) lua_getnumber(result);

    lua_endblock();

    return result_i;
}