Exemplo n.º 1
0
static int protected_(lua_State *L) {
    int status;
    lua_pushvalue(L, lua_upvalueindex(1));
    lua_insert(L, 1);
    status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, protected_cont);
    return protected_finish(L, status, 0);
}
Exemplo n.º 2
0
static int luaB_pcall (lua_State *L) {
  int status;
  luaL_checkany(L, 1);
  lua_pushnil(L);
  lua_insert(L, 1);  /* create space for status result */
  status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont);
  return finishpcall(L, (status == LUA_OK));
}
Exemplo n.º 3
0
static int luaB_pcall (lua_State *L) {
  int status;
  luaL_checkany(L, 1);
  lua_pushboolean(L, 1);  /* first result if no errors */
  lua_insert(L, 1);  /* put it in place */
  status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall);
  return finishpcall(L, status, 0);
}
Exemplo n.º 4
0
static int luaB_pcall (lua_State *L) {
  int status;
  luaL_checkany(L, 1);
  status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, pcallcont);
  luaL_checkstack(L, 1, NULL);
  lua_pushboolean(L, (status == LUA_OK));
  lua_insert(L, 1);
  return lua_gettop(L);  /* return status + all results */
}
Exemplo n.º 5
0
static int luaB_xpcall (lua_State *L) {
  int status;
  int n = lua_gettop(L);
  luaL_argcheck(L, n >= 2, 2, "value expected");
  lua_pushvalue(L, 1);  /* exchange function... */
  lua_copy(L, 2, 1);  /* ...and error handler */
  lua_replace(L, 2);
  status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 0, pcallcont);
  return finishpcall(L, (status == LUA_OK));
}
Exemplo n.º 6
0
/*
** Do a protected call with error handling. After 'lua_rotate', the
** stack will have <f, err, true, f, [args...]>; so, the function passes
** 2 to 'finishpcall' to skip the 2 first values when returning results.
*/
static int luaB_xpcall (lua_State *L) {
  int status;
  int n = lua_gettop(L);
  luaL_checktype(L, 2, LUA_TFUNCTION);  /* check error function */
  lua_pushboolean(L, 1);  /* first result */
  lua_pushvalue(L, 1);  /* function */
  lua_rotate(L, 3, 2);  /* move them below function's arguments */
  status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall);
  return finishpcall(L, status, 2);
}
Exemplo n.º 7
0
static int luaB_xpcall (lua_State *L) {
  int status;
  int n = lua_gettop(L);
  luaL_argcheck(L, n >= 2, 2, "value expected");
  lua_pushvalue(L, 1);  /* exchange function... */
  lua_copy(L, 2, 1);  /* ...and error handler */
  lua_replace(L, 2);
  status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 1, pcallcont);
  luaL_checkstack(L, 1, NULL);
  lua_pushboolean(L, (status == LUA_OK));
  lua_replace(L, 1);
  return lua_gettop(L);  /* return status + all results */
}
Exemplo n.º 8
0
void lua_timer_callback(uv_timer_t * timer)
{
	luatimer_t * tm = container_of(timer,luatimer_t,timer);
	lua_State * L = tm->L;
	if(LUA_NOREF != tm->ref_cb && LUA_NOREF != tm->ref)
	{
		int top = lua_gettop(L);
		lua_rawgeti(L, LUA_REGISTRYINDEX, tm->ref_cb); // ╩ь╣В
		lua_rawgeti(L, LUA_REGISTRYINDEX, tm->ref);		// втиМ
		if(LUA_OK == lua_pcallk(L, 1, LUA_MULTRET, 0, 0, NULL))
		{

		}
		lua_settop(L,top);
	}
}
Exemplo n.º 9
0
	void swig_lua_function_measure(nonius::chronometer& meter) {
		lua_State* L = luaL_newstate();
		lua_atpanic(L, panic_throw);
		lua_do_or_die(L, "function f (i) return i end");
		
		meter.measure([&]() {
			int x = 0;
			for (int i = 0; i < repetition; ++i) {
				lua_getglobal(L, "f");
				lua_pushinteger(L, i);
				lua_pcallk(L, 1, 1, LUA_NOREF, 0, nullptr);
				int v = static_cast<int>(lua_tointeger(L, -1));
				x += v;
				lua_pop(L, 1);
			}
			return x;
		});
	}
Exemplo n.º 10
0
bool
CLuaVM::execute(){
    /*
If errfunc is 0, then the error message returned on the stack is exactly the original error message. Otherwise, errfunc is the stack index of an error handler function. (In the current implementation, this index cannot be a pseudo-index.) In case of runtime errors, this function will be called with the error message and its return value will be the message returned on the stack by lua_pcall.
*/

// will push the error function  each time
    //int result = luabind::detail::pcall(getVM(), 0, LUA_MULTRET);

    // Aller chercher la fct d'erreur dans detail::pcall
    int result = 0;
    //result = luabind::detail::pcall(getVM(), 0, LUA_MULTRET);

		pcall_callback_fun e = get_pcall_callback();
		int en = 0;
		if ( e )
		{
			int base = lua_gettop(_vm);
			lua_pushcfunction(_vm, e);
			lua_insert(_vm, base);  // push pcall_callback under chunk and args
			en = base;
  		}
  		//int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,int ctx, lua_CFunction k);
		result = lua_pcallk(_vm, 0, 0, en,0,0);
        if ( en )
			lua_remove(_vm, en);  // remove pcall_callback


    // If we are here, it means there has been an error so we unwind stack
    if(result != 0){

        //_LOG_ERROR << "Error happened while executing";
        setErrorDescription(result);

        return false;
    }

    return true;
}
Exemplo n.º 11
0
int32_t context_lua_t::lua_ref_callback_entry(lua_State *L)
{
	int upvalue_count = 0;
	while (!lua_isnone(L, lua_upvalueindex(upvalue_count + 1))) {
		++upvalue_count;
	}
	ASSERT(upvalue_count > 1);
	lua_CFunction adjust_resume_args = (lua_CFunction)lua_touserdata(L, lua_upvalueindex(upvalue_count));
	if (adjust_resume_args) {
		adjust_resume_args(L);
	}
	--upvalue_count;
	int resume_count = lua_gettop(L);
	lua_checkstack(L, upvalue_count);
	lua_pushvalue(L, lua_upvalueindex(upvalue_count));
	lua_insert(L, 1); /* put callback closure as first arg */
	for (int i = 1; i < upvalue_count; ++i) {
		lua_pushvalue(L, lua_upvalueindex(i));
	}
	/* lua_callback_entry_continue makes the coroutine can be recovered. */
	int status = lua_pcallk(L, upvalue_count + resume_count - 1, LUA_MULTRET, 0, 0, lua_ref_callback_entry_continue);
	return lua_ref_callback_entry_finish(L, (status == LUA_OK));
}
Exemplo n.º 12
0
LUA_API int luaS_pcall(lua_State *L, int nargs, int nresults, int err) {
	return k(L, lua_pcallk(L, nargs, nresults, err, 0, k), 0);
}