Example #1
0
int luaU_UInt64Equal(lua_State* L)
{
	if( lua_gettop(L)!=2 )
	{
		ASSERT(false);
	}

	UINT64 left  = 0;
	UINT64 right = 0;
	if(lua_isnumber(L, 1))
	{
		double number = lua_tonumber(L, 1);
		memcpy(&left, &number, sizeof(UINT64));
	}
	else if(lua_islightuserdata(L, 1))
	{
		left = (UINT64)lua_touserdata(L, 1);
	}
	
	if(lua_isnumber(L, 2))
	{
		double number = lua_tonumber(L, 2);
		memcpy(&right, &number, sizeof(UINT64));
	}
	else if(lua_islightuserdata(L, 2))
	{
		right = (UINT64)lua_touserdata(L, 2);
	}

	lua_pushboolean(L,left==right );
	return 1;
}
Example #2
0
	// list, var
	static int objectIterator(lua_State* L)
	{
#ifndef ITERATOR_USE_USERDATA
		xassert(lua_islightuserdata(L, 1));
#else
		xassert(lua_isuserdata(L, 1) || lua_islightuserdata(L, 1));
#endif

		auto iterPtr = static_cast<ObjectIterPair*> (lua_touserdata(L, 1));

		if (iterPtr != nullptr && iterPtr->notEnd())
		{
			push<GameObject*>(L, *(*iterPtr));
			iterPtr->next();
		}
		else
		{
			lua_pushnil(L);
#ifndef ITERATOR_USE_USERDATA
			delete iterPtr;
#endif
		}

		return 1;
	}
Example #3
0
static int Lzmq_init(lua_State *L)
{
    zmq_ptr *ctx = lua_newuserdata(L, sizeof(zmq_ptr));
    luaL_getmetatable(L, MT_ZMQ_CONTEXT);
    lua_setmetatable(L, -2);

    if (lua_islightuserdata(L, 1)) {
        // Treat a light userdata as a raw ZMQ context object, which
        // we'll silently wrap.  (And we won't automatically call term
        // on it.)

        ctx->ptr = lua_touserdata(L, 1);
        ctx->should_free = 0;
        return 1;
    }

    int io_threads = luaL_checkint(L, 1);

    ctx->ptr = zmq_init(io_threads);

    if (!ctx->ptr) {
        return Lzmq_push_error(L);
    }

    // toboolean defaults to false, but we want a missing param #2
    // to mean true
    if (lua_isnil(L, 2)) {
        ctx->should_free = 1;
    } else {
        ctx->should_free = lua_toboolean(L, 2);
    }

    return 1;
}
Example #4
0
static int lib_iterateThinkers(lua_State *L)
{
	int state = luaL_checkoption(L, 1, "mobj", iter_opt);

	thinker_t *th = NULL;
	actionf_p1 searchFunc;
	const char *searchMeta;

	lua_settop(L, 2);
	lua_remove(L, 1); // remove state now.

	switch(state)
	{
		case 0:
			searchFunc = NULL;
			searchMeta = NULL;
			break;
		case 1:
		default:
			searchFunc = (actionf_p1)P_MobjThinker;
			searchMeta = META_MOBJ;
			break;
	}

	if (!lua_isnil(L, 1)) {
		if (lua_islightuserdata(L, 1))
			th = (thinker_t *)lua_touserdata(L, 1);
		else if (searchMeta)
			th = *((thinker_t **)luaL_checkudata(L, 1, searchMeta));
		else
			th = *((thinker_t **)lua_touserdata(L, 1));
	} else
		th = &thinkercap;

	if (!th) // something got our userdata invalidated!
		return 0;

	if (searchFunc == NULL)
	{
		if ((th = th->next) != &thinkercap)
		{
			if (th->function.acp1 == (actionf_p1)P_MobjThinker)
				LUA_PushUserdata(L, th, META_MOBJ);
			else
				lua_pushlightuserdata(L, th);
			return 1;
		}
		return 0;
	}

	for (th = th->next; th != &thinkercap; th = th->next)
	{
		if (th->function.acp1 != searchFunc)
			continue;

		LUA_PushUserdata(L, th, searchMeta);
		return 1;
	}
	return 0;
}
Example #5
0
static int l_etable_add(lua_State *L)
{
	struct aura_export_table *tbl;
	const char *name, *arg, *ret;

	TRACE();
	aura_check_args(L, 4);

	if (!lua_islightuserdata(L, 1))
		aura_typeerror(L, 1, "ludata");
	if (!lua_isstring(L, 2))
		aura_typeerror(L, 1, "string");
	if (!lua_isstring(L, 3))
		aura_typeerror(L, 1, "string");
	if (!lua_isstring(L, 4))
		aura_typeerror(L, 1, "string");

	tbl = lua_touserdata(L, 1);
	name = lua_tostring(L, 2);
	arg = lua_tostring(L, 3);
	ret = lua_tostring(L, 4);

	aura_etable_add(tbl, name, arg, ret);
	return 0;
}
Example #6
0
// local s = oid2str(oid)
int luaU_oid2str(lua_State* L)
{
	char buf[256];
	if(lua_isnumber(L, 1))
	{
		double number = lua_tonumber(L, 1);
		UINT64 val;
		memcpy(&val, &number, sizeof(UINT64));
		size_t l = sprintf_k(buf, sizeof(buf), "%lld", val);
		lua_pushlstring(L, buf, l);
		return 1;
	}
	else if(lua_islightuserdata(L, 1))
	{
		UINT64 val = (UINT64)lua_touserdata(L, 1);
		size_t l = sprintf_k(buf, sizeof(buf), "%lld", val);
		lua_pushlstring(L, buf, l);
		return 1;
	}
	else
	{
		luaL_argerror(L, 1, "arg:oid should be a number value");
		return 0;
	}
}
Example #7
0
int CLuaScript::LuaCallback(lua_State *lua)
{
	int iNumberIdx	 = lua_upvalueindex(1);
	int nRetsOnStack = 0;

	bool bRetVal = false;

	if (lua_istable(lua, 1))
	{
		lua_rawgeti(lua, 1, 0);

		if (lua_islightuserdata(lua, -1))
		{
			CLuaScript *pThis	= reinterpret_cast<CLuaScript*>(lua_touserdata(lua, -1));
			int			nMethod = static_cast<int>(lua_tonumber(lua, iNumberIdx));

			assert(!(nMethod > pThis->MethodsCount()));

			lua_remove(lua, 1); lua_remove(lua, -1);

			nRetsOnStack = pThis->ScriptCalling(pThis->Bridge(), nMethod);

			bRetVal = true;
		}
	}

	if (bRetVal == false)
	{
		lua_error(lua);
	}

	return nRetsOnStack;
}
Example #8
0
void* luaCompat_getPointer(lua_State* L, int index)
{ /* lua5 */
  if(!lua_islightuserdata(L, index))
    return NULL;

  return lua_touserdata(L, index);
}
Example #9
0
    int LuaSockAddr::sockAddrNewindex(lua_State *L)
    {
        // get field handler map from Lua registry
        StrPtrMap<FieldHandler *> *fhm = NULL;
        lua_pushlightuserdata(L, fhmRegKey());
        lua_gettable(L, LUA_REGISTRYINDEX);
        if (lua_islightuserdata(L, -1))
        {
            fhm = static_cast<StrPtrMap<FieldHandler *> *>
                  (lua_touserdata(L, -1));
        }
        if (!fhm)
        {
            luaL_error(L, "unable to retrieve field handler map");
        }
        lua_pop(L, 1);

        // call appropriate field handler
        int rc = 0;
        const char *key = luaL_checkstring(L, 2);
        const FieldHandler *fh = fhm->find(key);
        if (fh)
        {
            rc = fh->set(L);
        }
        else
        {
            luaL_error(L, "invalid apr_sockaddr_t field: %s", key);
        }

        return rc;
    }
Example #10
0
int LuaManager::SendClientMessage(lua_State* L) {
	if (lua_gettop(L) == 2 && lua_islightuserdata(L, -2) && lua_isstring(L, -1)) {
		Plugin::getInstance()->sendClientCommand(static_cast<ConnectionDataPtr>(lua_touserdata(L, -2)), lua_tostring(L, -1));
	}

	return 0;
}
Example #11
0
int LuaManager::SendHubMessage(lua_State* L) {
	if (lua_gettop(L) == 2 && lua_islightuserdata(L, -2) && lua_isstring(L, -1)) {
		Plugin::getInstance()->sendHubCommand(reinterpret_cast<HubDataPtr>(lua_touserdata(L, -2)), lua_tostring(L, -1));
	}

	return 0;
}
Example #12
0
int LuaManager::DeleteClient(lua_State* L) {
	if (lua_gettop(L) == 1 && lua_islightuserdata(L, -1)){
		Plugin::getInstance()->destroyHub(reinterpret_cast<HubDataPtr>(lua_touserdata(L, -1)));
	}

	return 0;
}
Example #13
0
static int lqtL_newindexfunc (lua_State *L) {
    if (!lua_isuserdata(L, 1) && lua_islightuserdata(L, 1)) return 0;
    lua_getmetatable(L, 1);
    lua_pushliteral(L, "__set");
    lua_rawget(L, -2);
    if (lua_istable(L, -1)) {
        lua_pushvalue(L, 2);
        lua_gettable(L, -2);
        if (lua_isfunction(L, -1)) {
            lua_CFunction setter = lua_tocfunction(L, -1);
            if (!setter) return luaL_error(L, "Invalid setter %s", lua_tostring(L, 2));
            return setter(L);
        }
    }
    lua_settop(L, 3); // (=3)
    lua_getfenv(L, 1); // (+1)
    if (!lua_istable(L, -1)) {
        lua_pop(L, 1); // (+0)
        return 0;
    }
    lua_remove(L, 1); // (+0)
    lua_insert(L, 1); // (+0)
    lua_rawset(L, 1); // (-2)
    return 0;
}
Example #14
0
int f_memcache_exists(lua_State *L) {
	char *r;
	int n = lua_gettop(L);
	struct memcache *mc;

	if (!lua_islightuserdata(L, lua_upvalueindex(1))) {
		lua_pushstring(L, "where is my userdata ?");
		lua_error(L);
	}

	mc = lua_touserdata(L, lua_upvalueindex(1));

	if (n != 1) {
		lua_pushstring(L, "expected one argument");
		lua_error(L);
	}

	if (!lua_isstring(L, 1)) {
		lua_pushstring(L, "argument has to be a string");
		lua_error(L);
	}

	if (NULL == (r = mc_aget(mc,
				 (char*) lua_tostring(L, 1), lua_strlen(L, 1)))) {

		lua_pushboolean(L, 0);
		return 1;
	}

	free(r);

	lua_pushboolean(L, 1);
	return 1;
}
Example #15
0
    ReadResult readNode( const std::string& fileStr, const osgDB::ReaderWriter::Options* options ) const
    {
        std::string ext( osgDB::getLowerCaseFileExtension(fileStr) );
        if( !acceptsExtension(ext) )
            return ReadResult::FILE_NOT_HANDLED;

        std::string fileName( osgDB::findDataFile( fileStr, options ) );
        if( fileName.empty() )
            return ReadResult::FILE_NOT_FOUND;

        osg::notify(osg::INFO)
                << "ReaderWriterLUA( \"" << fileName << "\" )" << std::endl;

        osgToy::LuaState L;
        if( luaL_loadfile( L, fileName.c_str()) || lua_pcall(L,0,1,0) )
        {
            osg::notify(osg::WARN) << "error in \"" << fileName << "\":\n"
                                   << lua_tostring(L,-1) << std::endl;
            return 0;
        }

        osg::Node* node(0);

        if( ! lua_islightuserdata(L,-1) )
        {
            osg::notify(osg::WARN) << "wrong lua return type \""
                                   << lua_typename(L,lua_type(L,-1)) << "\"" << std::endl;
        }
        else
        {
            node = static_cast<osg::Node*>( lua_touserdata(L,-1) );
        }
        return node;
    }
static int lua_subsample_yuyv2yuyv(lua_State *L){
  static std::vector<uint32_t> yuyv_array;

  // 1st Input: Original YUYV-format input image
  uint32_t *yuyv = (uint32_t *) lua_touserdata(L, 1);
  if ((yuyv == NULL) || !lua_islightuserdata(L, 1)) {
    return luaL_error(L, "Input YUYV not light user data");
  }
  // 2nd Input: Width (in YUYV macropixels) of the original YUYV image
  int m = luaL_checkint(L, 2);
  // 3rd Input: Height (in YUVY macropixels) of the original YUYV image
  int n = luaL_checkint(L, 3);
  // 4th Input: How much to subsample 
  int subsample_rate = luaL_checkint(L, 4);

  yuyv_array.resize( m*n/subsample_rate/subsample_rate );
  int yuyv_ind = 0;

  for (int j = 0; j < n; j++){
    for (int i = 0; i < m; i++) {
      if (((i%subsample_rate==0) && (j%subsample_rate==0)) || subsample_rate==1)	{
        yuyv_array[yuyv_ind++] = *yuyv;
      }
      yuyv++;
    }
  }

  // Pushing light data
  lua_pushlightuserdata(L, &yuyv_array[0]);
  return 1;
}
Example #17
0
//
// LUA_MarketGetName(product (object))
//
static int LUA_MarketGetName(lua_State *lua)
{
	int count = lua_gettop(lua);
	if (count < 1)
	{
		CzScriptEngineLua::DisplayError(lua, "market.name() not enough parameters, expected product (object)");
		lua_pushnil(lua);
		return 1;
	}

	// Get the product object
	CzMarketProduct* product = NULL;
	if (lua_islightuserdata(lua, 1))
		product = (CzMarketProduct*)lua_touserdata(lua, 1);
	else
	{
		CzScriptEngineLua::DisplayError(lua, "market.name(), invalid product for Param0");
		lua_pushnil(lua);
		return 1;
	}

	lua_pushstring(lua, product->Name.c_str());

	return 1;
}
Example #18
0
void GetFunction(const char *name, LexState *ls, Proto *fs)
{
	const int count1 = lua_gettop(ls->L);	
	lparser_callbacks::FunctionCallback callback = 0;

	if ((name == NULL) || (fs == NULL))
		return;

	if (strlen(name) <= 0)
		return;	

	lua_getglobal(ls->L, LUA_PARSER_DEBUG_TABLE);
	if (lua_istable(ls->L, -1))
	{
		lua_getfield(ls->L, -1, LUA_PARSER_CB_FUNC);
		if (lua_islightuserdata(ls->L, -1))
		{
			callback = (lparser_callbacks::FunctionCallback)lua_touserdata(ls->L, -1);
			if (callback != NULL)
				callback(name, fs->linedefined, fs->lastlinedefined);
		}
	}

	const int count2 = lua_gettop(ls->L);
	if ((count2 != count1) && (count2 > count1))
		lua_pop(ls->L, count2 - count1);
}
Example #19
0
static int luazmq_skt_reset_handle(lua_State *L) {
  zsocket *skt = luazmq_getsocket(L);
  void *src = lua_touserdata(L, 2);
  int own   =  lua_isnoneornil(L, 3) ? 
    ((skt->flags & LUAZMQ_FLAG_DONT_DESTROY)?0:1) :
    lua_toboolean(L, 3);
  int close = lua_toboolean(L, 4);
  void *h   = skt->skt;

  luaL_argcheck(L, lua_islightuserdata(L, 2), 2, "lightuserdata expected");

  skt->skt = src;
  if(own) skt->flags &= ~LUAZMQ_FLAG_DONT_DESTROY;
  else    skt->flags |=  LUAZMQ_FLAG_DONT_DESTROY;

  if(close){
    zmq_close(h);
    lua_pushboolean(L, 1);
  }
  else{
    lua_pushlightuserdata(L, h);
  }

  return 1;
}
Example #20
0
int ObjectBinding::index( lua_State* L )
{
	co::IObject** ud = reinterpret_cast<co::IObject**>( lua_touserdata( L, 1 ) );
	assert( ud );
	assert( lua_isstring( L, 2 ) );

	__BEGIN_EXCEPTIONS_BARRIER__

	co::IObject* object = *ud;

	if( isStringComponent( L, 2 ) )
	{
		LuaState::push( L, object->getComponent() );
		return 1;
	}

	if( pushMember( L, object->getComponent() ) )
	{
		assert( lua_islightuserdata( L, -1 ) );
		co::IPort* port = checkPort( L, -1 );
		co::IService* service = object->getServiceAt( port );
		LuaState::push( L, service );

		// notify interceptors
		for( co::Range<IInterceptor* const> r( sm_interceptors ); r; r.popFirst() )
			r.getFirst()->postGetService( object, port, service );
	}

	return 1;

	__END_EXCEPTIONS_BARRIER__
}
Example #21
0
static int lqtL_indexfunc (lua_State *L) {
    int i = 1;
    if (lua_isuserdata(L, 1) && !lua_islightuserdata(L, 1)) {
        lua_getfenv(L, 1); // (1)
        lua_pushvalue(L, 2); // (2)
        lua_gettable(L, -2); // (2)
        if (!lua_isnil(L, -1)) {
            lua_remove(L, -2);
            return 1;
        }
        lua_pop(L, 2); // (0)
    }
    lua_pushnil(L); // (+1)
    while (!lua_isnone(L, lua_upvalueindex(i))) { // (+1)
        lua_pop(L, 1); // (+0)
        lua_pushvalue(L, 2); // (+1)
        if (i==1) {
            lua_rawget(L, lua_upvalueindex(i)); // (+1)
        } else {
            lua_gettable(L, lua_upvalueindex(i)); // (+1)
        }
        if (!lua_isnil(L, -1)) break;
        i++;
    }
    return 1; // (+1)
}
Example #22
0
static int load_stuff(lua_State *L)
{
    struct load_ctx *ctx = lua_touserdata(L, -1);
    lua_pop(L, 1); // -
    struct vf_instance *vf = ctx->vf;
    struct vf_priv_s *p = vf->priv;

    // setup stuff; should be idempotent
    lua_pushlightuserdata(L, vf);
    lua_setfield(L, LUA_REGISTRYINDEX, "p"); // -
    lua_pushcfunction(L, l_invoke);
    lua_setglobal(L, "invoke");

    FUCKYOUOHGODWHY(L);
    vsmap_to_table(L, lua_gettop(L), ctx->vars);
    if (luaL_dofile(L, p->cfg_file))
        lua_error(L);
    lua_pop(L, 1);

    lua_getglobal(L, "video_out"); // video_out
    if (!lua_islightuserdata(L, -1))
        luaL_error(L, "video_out not set or has wrong type");
    p->out_node = p->vsapi->cloneNodeRef(lua_touserdata(L, -1));
    return 0;
}
Example #23
0
/* Type casting
*/
static int tolua_bnd_cast (lua_State* L)
{

/* // old code
        void* v = tolua_tousertype(L,1,NULL);
        const char* s = tolua_tostring(L,2,NULL);
        if (v && s)
         tolua_pushusertype(L,v,s);
        else
         lua_pushnil(L);
        return 1;
*/

	void* v;
	const char* s;
	if (lua_islightuserdata(L, 1)) {
		v = tolua_touserdata(L, 1, NULL);
	} else {
		v = tolua_tousertype(L, 1, 0);
	};

	s = tolua_tostring(L,2,NULL);
	if (v && s)
	 tolua_pushusertype(L,v,s);
	else
	 lua_pushnil(L);
	return 1;
}
Example #24
0
static int QPSolver_run(lua_State *L)
{
  SVQP2 *qp = (SVQP2*)luaT_checkudata(L, 1, QPSolver_id);
  luaL_argcheck(L, lua_isfunction(L, 2) || luaT_isudata(L, 2, torch_Tensor_id), 2, "function or Tensor expected");

  if(lua_isfunction(L, 2))
  {
    bool initialize = luaT_optboolean(L, 3, true);
    bool finalize = luaT_optboolean(L, 4, true);
    qp->Aclosure = L;
    qp->Afunction = QPSolver_luaClosure;
    int result = qp->run(initialize, finalize);
    if(result == -1)
      luaL_error(L, qp->errmsg);
    return 0;
  }
  else
  {
    bool initialize = luaT_optboolean(L, 4, true);
    bool finalize = luaT_optboolean(L, 5, true);
    
    THTensor *data = (THTensor*)luaT_checkudata(L, 2, torch_Tensor_id);
    luaL_argcheck(L, data->nDimension == 2, 2, "2D Tensor expected");
    luaL_argcheck(L, data->size[1] == qp->n, 2, "invalid size");
    
    struct QPSolver_cClosureParams stuff;
    
    lua_getfield(L, 3, "__eval");
    bool isCKernel = lua_islightuserdata(L, -1);
    lua_pop(L, 1);
    if(isCKernel)
    {
      double (*func)(THTensor*, THTensor*, void *) = ( double (*)(THTensor*, THTensor*, void *))luaT_getfieldchecklightudata(L, 3, "__eval");
      void *params = luaT_getfieldchecklightudata(L, 3, "__params");
      stuff.func = func;
      stuff.params = params;
    }
    else
    {
      lua_getfield(L, 3, "eval");
      lua_pushvalue(L, 3);
      stuff.func = NULL;
      stuff.params = NULL;
    }
    
    stuff.L = L;
    stuff.data = data;
    stuff.x1 = THTensor_new();
    stuff.x2 = THTensor_new();
    luaT_pushudata(L, stuff.x1, torch_Tensor_id); /* auto dealloc */
    luaT_pushudata(L, stuff.x2, torch_Tensor_id); /* auto dealloc */
    
    qp->Aclosure = &stuff;
    qp->Afunction = (stuff.func ? QPSolver_cClosure : QPSolver_cLuaClosure);
    int result = qp->run(initialize, finalize);
    if(result == -1)
      luaL_error(L, qp->errmsg);
    return 0;
  }
}
Example #25
0
/**
 * mosync.SysStringToBuffer(string, buffer)
 *
 * Copy contents of a Lua string to a C-buffer
 * pointed to by "buffer".
 * Does NOT copy the terminating null character.
 * Buffer must be large enough to hold string data.
 * Return true on success, false on error.
 */
static int luaStringToBuffer(lua_State *L)
{
	// Get pointer to Lua string.
	const char* s = luaL_checkstring(L, 1);

	// Get pointer to buffer.
	if (!lua_isnoneornil(L, 2) && lua_islightuserdata(L, 2))
	{
		char* buffer = (char*) lua_touserdata(L, 2);
		if (NULL != buffer)
		{
			// Copy to buffer.
			memcpy(buffer, s, strlen(s));

			lua_pushboolean(L, 1);
		}
		else
		{
			lua_pushboolean(L, 0);
		}
	}
	else
	{
		lua_pushboolean(L, 0);
	}

	return 1; // Number of results
}
Example #26
0
static int
ts_lua_cache_close(lua_State *L)
{
    int                     n;
    ts_lua_cont_info        *ci;
    ts_lua_cache_info       *info;

    ci = ts_lua_get_cont_info(L);
    if (ci == NULL)
        return 0;

    n = lua_gettop(L);
    if (n < 1) {
        return luaL_error(L, "'ts.cache_close' requires parameter");
    }

    /* table */
    if (!lua_istable(L, 1)) {
        return luaL_error(L, "'ts.cache_close' first param is not valid");
    }

    lua_pushlstring(L, "info", sizeof("info") - 1);
    lua_gettable(L, 1);

    if (!lua_islightuserdata(L, -1)) {
        return luaL_error(L, "'ts.cache_close' first param is not valid");
    }

    info = (ts_lua_cache_info*)lua_touserdata(L, -1);
    lua_pop(L, 1);

    ts_lua_release_cache_info(info, 0);

    return 0;
}
Example #27
0
int falco_rules::add_filter(lua_State *ls)
{
	if (! lua_islightuserdata(ls, -3) ||
	    ! lua_isstring(ls, -2) ||
	    ! lua_istable(ls, -1))
	{
		throw falco_exception("Invalid arguments passed to add_filter()\n");
	}

	falco_rules *rules = (falco_rules *) lua_topointer(ls, -3);
	const char *rulec = lua_tostring(ls, -2);

	list<uint32_t> evttypes;

	lua_pushnil(ls);  /* first key */
	while (lua_next(ls, -2) != 0) {
                // key is at index -2, value is at index
                // -1. We want the keys.
		evttypes.push_back(luaL_checknumber(ls, -2));

		// Remove value, keep key for next iteration
		lua_pop(ls, 1);
	}

	std::string rule = rulec;
	rules->add_filter(rule, evttypes);

	return 0;
}
Example #28
0
static gint
luaH_webview_eval_js(lua_State *L)
{
    WebKitWebFrame *frame = NULL;
    widget_t *w = luaH_checkwidget(L, 1);
    WebKitWebView *view = WEBKIT_WEB_VIEW(g_object_get_data(G_OBJECT(w->widget), "webview"));
    const gchar *script = luaL_checkstring(L, 2);
    const gchar *filename = luaL_checkstring(L, 3);

    /* Check if js should be run on currently focused frame */
    if (lua_gettop(L) >= 4) {
        if (lua_islightuserdata(L, 4)) {
            frame = lua_touserdata(L, 4);
        } else if (lua_toboolean(L, 4)) {
            frame = webkit_web_view_get_focused_frame(view);
        }
    }
    /* Fall back on main frame */
    if (!frame)
        frame = webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(view));

    /* evaluate javascript script and push return result onto lua stack */
    const gchar *result = webview_eval_js(frame, script, filename);
    lua_pushstring(L, result);
    return 1;
}
Example #29
0
// Extract pointer of userdata from the lua registry
static void *extract_registry(lua_State *L, const char *name) {
	lua_getfield(L, LUA_REGISTRYINDEX, REGISTRY_NAME);
	lua_getfield(L, -1, name);
	ASSERT(lua_islightuserdata(L, -1));
	void *result = lua_touserdata(L, -1);
	lua_pop(L, 2);
	return result;
}
	inline int __call_object_function(lua_State * L)
	{
		assert(lua_islightuserdata(L,lua_upvalueindex(2)));

		mem_handle * handle = (mem_handle *)lua_touserdata(L,lua_upvalueindex(2));

		return handle->call(L);
	}