Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use GLib.HashTable in Genie

Tags:

vala

genie

How can I access GLib.HashTable in Genie? I am trying to write a handler method for libsoup HTTP server. The query parameter is a GLib.HashTable. When I try to access query e.g. with

def search_handler (server : Soup.Server, msg : Soup.Message, path : string, 
                query : GLib.HashTable?, client : Soup.ClientContext)
 response_text : string = null
 if query is not null && query.contains("expr")
     response_text = get_search(query.get("expr"))

I got the error:

error: missing generic type arguments
    response_text = get_search(query.get("expr"))
                               ^^^^^

The only way I found is to make a new HashTable object:

p : GLib.HashTable of string, string = query
expr : string = p.get("expr")

What is the right way to handle this?

like image 471
user2235450 Avatar asked Nov 26 '25 08:11

user2235450


2 Answers

My be you can try with : dict of string,string

var d = new dict of string,string
d["one"]="1"
d["two"]="2"
print "%s",d["one"]
like image 103
txasatonga Avatar answered Nov 27 '25 21:11

txasatonga


something like this

[indent=4]

init
    var h = new HashTable of string, int (str_hash, str_equal)
    h["foo"] = 123
    h["bar"] = 456

    foo ("foo", h)


def foo (key: string, hash: HashTable of string, int)
    // PUT HASHTABLE IN THE END
    if hash.contains (key)
        stdout.printf ("%s => %i", key, hash[key])
like image 39
foo bar Avatar answered Nov 27 '25 21:11

foo bar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!