Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool-module
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool-module
Commits
0962caf2
Commit
0962caf2
authored
2 years ago
by
Georgy Moshkin
Browse files
Options
Downloads
Patches
Plain Diff
test(tlua): test receiving lua functions as callback arguments
parent
2540ccd5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!237
test(tlua): test receiving lua functions as callback arguments
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/src/lib.rs
+1
-0
1 addition, 0 deletions
tests/src/lib.rs
tests/src/tlua/functions_write.rs
+27
-0
27 additions, 0 deletions
tests/src/tlua/functions_write.rs
with
28 additions
and
0 deletions
tests/src/lib.rs
+
1
−
0
View file @
0962caf2
...
...
@@ -269,6 +269,7 @@ fn run_tests(cfg: TestConfig) -> Result<bool, io::Error> {
tlua
::
functions_write
::
pcall
,
tlua
::
functions_write
::
error
,
tlua
::
functions_write
::
optional_params
,
tlua
::
functions_write
::
lua_function_as_argument
,
tlua
::
any
::
read_numbers
,
tlua
::
any
::
read_hashable_numbers
,
tlua
::
any
::
read_strings
,
...
...
This diff is collapsed.
Click to expand it.
tests/src/tlua/functions_write.rs
+
27
−
0
View file @
0962caf2
...
...
@@ -322,3 +322,30 @@ pub fn optional_params() {
"Sup, Sailor!"
);
}
pub
fn
lua_function_as_argument
()
{
let
lua
=
Lua
::
new
();
let
my_data
=
std
::
rc
::
Rc
::
new
(
std
::
cell
::
Cell
::
new
(
0
));
let
my_data_in_lua
=
my_data
.clone
();
lua
.set
(
"apply_to_my_data"
,
Function
::
new
(
move
|
lua
:
tlua
::
StaticLua
|
{
let
f
:
tlua
::
LuaFunction
<
_
>
=
(
&
lua
)
.read_at
(
1
)
.unwrap
();
if
let
Ok
(
y
)
=
(
&
lua
)
.read_at
::
<
i32
>
(
2
)
{
my_data_in_lua
.set
(
f
.call_with_args
(
&
(
my_data_in_lua
.get
(),
y
))
.unwrap
());
}
else
{
my_data_in_lua
.set
(
f
.call_with_args
(
my_data_in_lua
.get
())
.unwrap
());
}
}),
);
assert_eq!
(
my_data
.get
(),
0
);
lua
.exec
(
"apply_to_my_data(function(x) return x + 1 end)"
)
.unwrap
();
assert_eq!
(
my_data
.get
(),
1
);
lua
.exec
(
"apply_to_my_data(function(x) return 42 end)"
)
.unwrap
();
assert_eq!
(
my_data
.get
(),
42
);
lua
.exec
(
"apply_to_my_data(function(x, y) return x + y end, 27)"
)
.unwrap
();
assert_eq!
(
my_data
.get
(),
69
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment