3

如何在 Genie 中访问 GLib.HashTable?我正在尝试为 libsoup HTTP 服务器编写一个处理程序方法。查询参数是一个 GLib.HashTable。当我尝试访问查询时,例如

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"))

我得到了错误:

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

我发现的唯一方法是创建一个新的 HashTable 对象:

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

处理这个问题的正确方法是什么?

4

2 回答 2

1

你可以试试:字符串字典,字符串

var d = new dict of string,string
d["one"]="1"
d["two"]="2"
print "%s",d["one"]
于 2013-04-08T22:48:20.777 回答
1

像这样的东西

[缩进=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])
于 2015-07-10T21:31:26.293 回答