[Tarantool-patches] [PATCH v17 1/2] box/cmod: implement cmod Lua module
Cyrill Gorcunov
gorcunov at gmail.com
Wed Feb 10 15:38:47 MSK 2021
On Wed, Feb 10, 2021 at 03:24:47PM +0300, Cyrill Gorcunov wrote:
>
> Once successfully loaded we can execute it. Note that unlike regular
> Lua functions the context of `C` functions is different. They never
> thrown an exception but return `true|nil, res` form where first value
> set to `nil` in case of error condition and `res` carries an error
> description.
>
> Lets call the `cfunc_sum` with wrong number of arguments
Typo left in description. I force pushed an update (we always throw
an exception.
---
First we should load it as
``` Lua
m = require('cmod').load('cfunc')
cfunc_sum = m:load('cfunc_sum')
```
Once successfully loaded we can execute it. Lets call the
`cfunc_sum` with wrong number of arguments
``` Lua
cfunc_sum()
| ---
| - error: invalid argument count
```
We will see the `"invalid argument count"` message in output.
The error message has been set by the `box_error_set` in `C`
code above.
On success the sum of arguments will be printed out.
``` Lua
cfunc_sum(1, 2)
| ---
| - 3
```
More information about the Tarantool-patches
mailing list