/**
 * get a field from the result-set
 *
 */
static int proxy_resultset_fields_get(lua_State *L) {
	GRef *ref = *(GRef **)luaL_checkself(L);
	proxy_resultset_t *res = ref->udata;
	GPtrArray *fields = res->fields;
	MYSQL_FIELD *field;
	MYSQL_FIELD **field_p;
	lua_Integer ndx = luaL_checkinteger(L, 2);

	/* protect the compare */
	if (fields->len > G_MAXINT) {
		return 0;
	}
    
	if (ndx < 1 || ndx > (lua_Integer)fields->len) {
		lua_pushnil(L);
        
		return 1;
	}
    
	field = fields->pdata[ndx - 1]; /** lua starts at 1, C at 0 */
    
	field_p = lua_newuserdata(L, sizeof(field));
	*field_p = field;
    
	proxy_getmetatable(L, methods_proxy_resultset_fields_field);
	lua_setmetatable(L, -2);
    
	return 1;
}
Example #2
0
int sql_tokenizer_lua_token_getmetatable(lua_State *L) {
	static const struct luaL_reg methods[] = {
		{ "__index", proxy_tokenize_token_get },
		{ NULL, NULL },
	};
	return proxy_getmetatable(L, methods);
}	
int lua_mysqld_column_getmetatable(lua_State *L) {
	static const struct luaL_reg methods[] = {
		{ "__index", lua_mysqld_column_get },
		{ NULL, NULL },
	};
	return proxy_getmetatable(L, methods);
}
Example #4
0
int network_socket_lua_getmetatable(lua_State *L) {
    static const struct luaL_reg methods[] = {
        { "__index", proxy_socket_get },
        { NULL, NULL },
    };
    return proxy_getmetatable(L, methods);
}
Example #5
0
int network_clientip_vec_lua_getmetatable(lua_State *L) {
       static const struct luaL_reg methods[] = {
              {"__index", proxy_clientip_get },
              {"__len", proxy_clientip_vec_len },
              {NULL, NULL },
       };

       return proxy_getmetatable(L, methods);
}
Example #6
0
static int sql_tokenizer_lua_getmetatable(lua_State *L) {
	static const struct luaL_reg methods[] = {
		{ "__index", proxy_tokenize_get },
		{ "__newindex", proxy_tokenize_set },
		{ "__len",   proxy_tokenize_len },
		{ "__gc",   proxy_tokenize_gc },
		{ NULL, NULL },
	};
	return proxy_getmetatable(L, methods);
}	
Example #7
0
int network_backends_lua_getmetatable(lua_State *L) {
	static const struct luaL_reg methods[] = {
		{ "__index", proxy_backends_get },
		{ "__newindex", proxy_backends_set },
		{ "__len", proxy_backends_len },
		{ NULL, NULL },
	};

	return proxy_getmetatable(L, methods);
}
static int proxy_resultset_lua_push_ref(lua_State *L, GRef *ref) {
	GRef **ref_p;

	g_ref_ref(ref);
	
	ref_p = lua_newuserdata(L, sizeof(GRef *));
	*ref_p = ref;

	proxy_getmetatable(L, methods_proxy_resultset);
	lua_setmetatable(L, -2);

	return 1;
}
static int proxy_resultset_lua_push(lua_State *L, proxy_resultset_t *_res) {
	GRef **ref_p;
	GRef *ref;

	ref = g_ref_new();
	g_ref_set(ref, _res, (GDestroyNotify)proxy_resultset_free);
	
	ref_p = lua_newuserdata(L, sizeof(GRef *));
	*ref_p = ref;

	proxy_getmetatable(L, methods_proxy_resultset);
	lua_setmetatable(L, -2);

	return 1;
}
/**
 * Push a metatable onto the Lua stack containing methods to 
 * access the resultsets.
 */
void proxy_getinjectionmetatable(lua_State *L) {
    proxy_getmetatable(L, methods_proxy_injection);
}
/**
 * Push a metatable onto the Lua stack containing methods to 
 * handle the query injection queue.
 */
void proxy_getqueuemetatable(lua_State *L) {
    proxy_getmetatable(L, methods_proxy_queue);
}