Example #1
0
void GrimEngine::luaUpdate() {
	// Update timing information
	unsigned newStart = g_system->getMillis();
	if (newStart < _frameStart) {
		_frameStart = newStart;
		return;
	}
	_frameTime = newStart - _frameStart;
	_frameStart = newStart;

	_frameTimeCollection += _frameTime;
	if (_frameTimeCollection > 10000) {
		_frameTimeCollection = 0;
		lua_collectgarbage(0);
	}

	lua_beginblock();
	setFrameTime(_frameTime);
	lua_endblock();

	lua_beginblock();
	setMovieTime(_movieTime);
	lua_endblock();

	// Run asynchronous tasks
	lua_runtasks();
}
Example #2
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);
}
Example #3
0
bool LuaBase::callback(const char *name, const LuaObjects &objects) {
	lua_beginblock();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring(name);
	lua_Object table = lua_gettable();

	if (lua_istable(table)) {
		lua_pushobject(table);
		lua_pushstring(name);
		lua_Object func = lua_gettable();
		if (lua_isfunction(func)) {
			lua_pushobject(table);
			objects.pushObjects();
			lua_callfunction(func);
		} else {
			lua_endblock();
			return false;
		}
	} else if (lua_isfunction(table)) {
		objects.pushObjects();
		lua_callfunction(table);
	} else if (!lua_isnil(table)) {
		lua_endblock();
		return false;
	}

	lua_endblock();
	return true;
}
Example #4
0
void GrimEngine::handleUserPaint() {
	lua_Object func;

	lua_beginblock();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("userPaintHandler");
	lua_Object handler = lua_gettable();
	if (lua_istable(handler)) {
		lua_pushobject(handler);
		lua_pushstring("userPaintHandler");
		func = lua_gettable();
		if (!lua_isfunction(func))
			error("handleUserPaint: handler not a function");
		lua_pushobject(handler);
	} else if (lua_isfunction(handler)) {
		func = handler;
	} else if (!lua_isnil(handler)) {
		error("handleUserPaint: invalid handler");
		return;
	} else {
		lua_endblock();
		return;
	}

	lua_callfunction(func);

	lua_endblock();
}
Example #5
0
void GrimEngine::savegameCallback() {
	lua_Object funcParam1;

	lua_beginblock();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("saveGameCallback");
	lua_Object funcParam2 = lua_gettable();

	if (lua_istable(funcParam2)) {
		lua_pushobject(funcParam2);
		lua_pushstring("saveGameCallback");
		funcParam1 = lua_gettable();
		if (lua_isfunction(funcParam1)) {
			lua_pushobject(funcParam2);
			lua_callfunction(funcParam1);
		} else {
			error("GrimEngine::savegameCallback: handler is not a function");
		}
	} else if (lua_isfunction(funcParam2)) {
		funcParam1 = funcParam2;
		lua_callfunction(funcParam1);
	} else if (!lua_isnil(funcParam2)) {
		error("GrimEngine::savegameCallback: invalid handler");
	}
	lua_endblock();
}
Example #6
0
static void manual_input (int prompt) {
    int cont = 1;
    while (cont) {
        char buffer[BUFSIZ];
        int i = 0;
        lua_beginblock();
        if (prompt)
            printf("%s", lua_getstring(lua_getglobal("_PROMPT")));
        for(;;) {
            int c = getchar();
            if (c == EOF) {
                cont = 0;
                break;
            }
            else if (c == '\n') {
                if (i>0 && buffer[i-1] == '\\')
                    buffer[i-1] = '\n';
                else break;
            }
            else if (i >= BUFSIZ-1) {
                fprintf(stderr, "lua: argument line too long\n");
                break;
            }
            else buffer[i++] = (char)c;
        }
        buffer[i] = '\0';
        ldo(lua_dostring, buffer);
        lua_endblock();
    }
    printf("\n");
}
Example #7
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;
}
Example #8
0
static void GetClassAttributes(void)
{
  int max_n = luaL_check_int(2);
  char **names = (char **) malloc(max_n * sizeof(char *));
  int n = IupGetClassAttributes(luaL_check_string(1), names, max_n);
  lua_Object tb;
  int i;

  if (n == -1)
  {
    lua_pushnil();
    return;
  }

  tb = lua_createtable();
  for (i = 0; i < n; i++) 
  {
    lua_beginblock();
    lua_pushobject(tb);
    lua_pushnumber(i);
    lua_pushstring(names[i]);
    lua_settable();
    lua_endblock();                /* end a section and starts another */
  }

  lua_pushobject(tb);
  lua_pushnumber(n);
  free(names);
}
Example #9
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);
}
Example #10
0
void LuaBase::update(int frameTime, int movieTime) {
	_frameTimeCollection += frameTime;
	if (_frameTimeCollection > 10000) {
		_frameTimeCollection = 0;
		lua_collectgarbage(0);
	}

	lua_beginblock();
	setFrameTime(frameTime);
	lua_endblock();

	lua_beginblock();
	setMovieTime(movieTime);
	lua_endblock();

	// Run asynchronous tasks
	lua_runtasks();
}
Example #11
0
static Ihandle* checkihandle_table(lua_Object tab, int index)
{
  Ihandle* ih;
  lua_Object o;
  lua_beginblock();
  lua_pushobject(tab);
  lua_pushnumber(index);
  o = lua_gettable();
  luaL_arg_check(lua_tag(o)==iuplua_tag, index, "handle expected");
  ih = (Ihandle*)lua_getuserdata(o);
  lua_endblock();
  return ih;
}
Example #12
0
void Lua_V1::postRestoreHandle() {
	lua_beginblock();

	if (g_grim->getGameType() == GType_GRIM) {
		// Set the developerMode, since the save contains the value of
		// the installation it was made with.
		lua_pushobject(lua_getglobal("developerMode"));
		bool devMode = g_registry->getBool("good_times");
		pushbool(devMode);
		lua_setglobal("developerMode");
		lua_endblock();
	}

	// Starting a movie calls the function 'music_state.pause()', which saves the current sfx volume to a temp
	// variable and sets it to 0. When the movie finishes 'music_state.unpause()' will be called, which reads
	// the volume from the temp variable and sets it. But if we have modified the sfx volume in the options
	// and than load a savegame made during a movie, at the end of the movie the temp variable will have the
	// old value. So here we call 'music_state.pause()' again, so that it can set the right value to the
	// temp variable.
	lua_beginblock();
	lua_Object o = lua_getglobal("music_state");
	if (!lua_isnil(o)) {
		lua_pushobject(o);
		lua_pushstring("paused");
		if (!lua_isnil(lua_gettable())) {
			lua_pushobject(o);
			lua_pushstring("paused");
			pushbool(false);
			lua_settable();

			lua_pushobject(o);
			lua_pushstring("pause");
			lua_Object func = lua_gettable();
			lua_pushobject(o);
			lua_callfunction(func);
		}
	}
	lua_endblock();
}
Example #13
0
static void cameraPostChangeHandle(int num) {
	lua_beginblock();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("postCamChangeHandler");
	lua_Object func = lua_gettable();

	if (lua_isfunction(func)) {
		lua_pushnumber(num);
		lua_callfunction(func);
	}

	lua_endblock();
}
Example #14
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;
}
Example #15
0
static int param_action(Ihandle* dialog, int param_index, void* user_data)
{
  int ret = 1;
  getparam_data* gp = (getparam_data*)user_data;
  if (gp->has_func)
  {
    lua_Object func;
    lua_beginblock();
    func = lua_getref(gp->func_ref);
    iuplua_pushihandle(dialog);
    lua_pushnumber(param_index);
    lua_callfunction(func);
    ret = (int)luaL_check_number(1);
    lua_endblock();
  }
  return ret;
}
Example #16
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;
}
Example #17
0
void Lua_V1::postRestoreHandle() {
	// Apply the patch, only if it wasn't applied already.
	if (lua_isnil(lua_getglobal("  service_release.lua"))) {
		if (bundle_dofile("patch05.bin") == 2)
			single_dofile("patch05.bin");
	}


	lua_beginblock();
	// Set the developerMode, since the save contains the value of
	// the installation it was made with.
	lua_pushobject(lua_getglobal("developerMode"));
	const char *devMode = g_registry->get("good_times", "");
	if (devMode[0] == 0)
		lua_pushnil();
	else
		lua_pushstring(devMode);
	lua_setglobal("developerMode");
	lua_endblock();
}
Example #18
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;
}
Example #19
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();
  }
}
Example #20
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;
}
Example #21
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;
}
Example #22
0
static void GetAllDialogs(void)
{
  int max_n = luaL_check_int(1);
  char **names = (char **) malloc(max_n * sizeof(char *));
  int i;
  int n = IupGetAllDialogs(names, 100);

  lua_Object tb = lua_createtable();
  for (i = 0; i < n; i++) 
  {
    lua_beginblock();
    lua_pushobject(tb);
    lua_pushnumber(i);
    lua_pushstring(names[i]);
    lua_settable();
    lua_endblock();                /* end a section and starts another */
  }

  lua_pushobject(tb);
  lua_pushnumber(n);
  free(names);
}
Example #23
0
static int TREE_multiunselection (Ihandle *handle, int *ids, int n)
{
  int i;
  lua_Object tb;

  iuplua_call_start(handle, "multiunselection");

  tb = lua_createtable();
  for (i = 0; i < n; i++) 
  {
    lua_beginblock();
    lua_pushobject(tb);
    lua_pushnumber(i+1);
    lua_pushnumber(ids[i]);
    lua_settable();
    lua_endblock();   
  }
  lua_pushobject(tb);

  lua_pushnumber (n);
  return iuplua_call();
}
Example #24
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);
}
Example #25
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;
}
Example #26
0
void GrimEngine::handleChars(int operation, int key, int /*keyModifier*/, uint16 ascii) {
	lua_Object func;
	char keychar[2];

	if (!CHAR_KEY(ascii))
		return;

	lua_beginblock();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("characterHandler");
	lua_Object handler = lua_gettable();
	if (lua_istable(handler)) {
		lua_pushobject(handler);
		lua_pushstring("characterHandler");
		func = lua_gettable();
		if (!lua_isfunction(func))
			error("handleChars: handler not a function");
		lua_pushobject(handler);
	} else if (lua_isfunction(handler)) {
		func = handler;
	} else if (!lua_isnil(handler)) {
		error("handleChars: invalid handler");
		return;
	} else {
		lua_endblock();
		return;
	}

	keychar[0] = ascii;
	keychar[1] = 0;
	lua_pushstring(keychar);
	lua_callfunction(func);

	lua_endblock();
}
Example #27
0
void GrimEngine::handleControls(int operation, int key, int /*keyModifier*/, uint16 ascii) {
	lua_Object buttonFunc, joyFunc;
	bool buttonFuncIsTable, joyFuncIsTable;

	// If we're not supposed to handle the key then don't
	if (!_controlsEnabled[key])
		return;

	lua_beginblock();

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("buttonHandler");
	lua_Object buttonHandler = lua_gettable();
	if (lua_istable(buttonHandler)) {
		lua_pushobject(buttonHandler);
		lua_pushstring("buttonHandler");
		buttonFunc = lua_gettable();
		if (!lua_isfunction(buttonFunc)) {
			error("handleControls: button handler not a function");
			return;
		}
		buttonFuncIsTable = true;
	} else if (lua_isfunction(buttonHandler)) {
		buttonFunc = buttonHandler;
		buttonFuncIsTable = false;
	} else {
		error("handleControls: invalid keys handler");
		return;
	}

	lua_pushobject(lua_getref(refSystemTable));
	lua_pushstring("axisHandler");
	lua_Object joyHandler = lua_gettable();
	if (lua_istable(joyHandler)) {
		lua_pushobject(joyHandler);
		lua_pushstring("axisHandler");
		joyFunc = lua_gettable();
		if (!lua_isfunction(joyFunc)) {
			error("handleControls: joystick handler not a function");
			return;
		}
		joyFuncIsTable = true;
	} else if (lua_isfunction(joyHandler)) {
		joyFunc = joyHandler;
		joyFuncIsTable = false;
	} else {
		error("handleControls: invalid joystick handler");
		return;
	}
	if (buttonFuncIsTable)
		lua_pushobject(buttonHandler);
	lua_pushnumber(key);
	if (operation == Common::EVENT_KEYDOWN) {
		lua_pushnumber(1);
		lua_pushnumber(1);
	} else {
		lua_pushnil();
		lua_pushnumber(0);
	}
	lua_pushnumber(0);
	lua_callfunction(buttonFunc);

	if (operation == Common::EVENT_KEYDOWN)
		_controlsState[key] = true;
	else if (operation == Common::EVENT_KEYUP)
		_controlsState[key] = false;

	lua_endblock();
}
Example #28
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);
}
Example #29
0
void iuplua_call_start(Ihandle* handle, char* name)
{                              
  lua_beginblock();
  lua_pushstring(name);
  lua_pushusertag(handle, iuplua_tag);
}