Reputation: 17422
there is an object client
which has many method, methods could be call like client:hget(key, field)
or client:exists(key)
etc.
Now, I need implement a function client_holder.call(cmd, ...)
local client = client_instance;
function call(cmd, ...)
client[cmd](client, ...) // will this work??
end
Upvotes: 1
Views: 139
Reputation: 69924
Yes, that should work. As the Lua manual states, the colon notation is just syntactic sugar:
The form
functioncall ::= prefixexp ‘:’ Name args
can be used to call "methods". A call v:name(args) is syntactic sugar for v.name(v,args), except that v is evaluated only once.
Upvotes: 2