Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use eval with custom args #11

Closed
alexeyknyshev opened this issue Feb 4, 2016 · 2 comments
Closed

How to use eval with custom args #11

alexeyknyshev opened this issue Feb 4, 2016 · 2 comments

Comments

@alexeyknyshev
Copy link

For example, I have this lua script for determining name of box.space by id:

tnt.Eval("box.space." + spaceIdStr + ".name", []interface{}{})

It seems to be ugly and error prone way. So how can I pass some data to lua and how to use this data as lua varable(s)?

@mialinx
Copy link

mialinx commented Feb 4, 2016

  1. define stored lua procedure in your init.lua (or another lua module) loaded in tarantool.
    For instance
function name2id(name)
   local id = 42
   return id  // result is scalar value here
end
  1. use Call to get the result
resp, err := connection.Call("name2id", []interface{}{ "users" })
if err != nil {
  return err
}
uid := resp.Data[0].([]interface{})[0].(uint64)    // Data is table of 1 tuple of 1 element here

@mialinx mialinx closed this as completed Feb 4, 2016
@alexeyknyshev
Copy link
Author

alexeyknyshev commented Feb 4, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants