Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Commits
333fc034
Commit
333fc034
authored
11 years ago
by
Roman Tsisyk
Browse files
Options
Downloads
Patches
Plain Diff
Temporary changes
parent
bcbc2f87
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/box/lua/tuple.cc
+0
-53
0 additions, 53 deletions
src/box/lua/tuple.cc
src/box/lua/tuple.lua
+26
-2
26 additions, 2 deletions
src/box/lua/tuple.lua
with
26 additions
and
55 deletions
src/box/lua/tuple.cc
+
0
−
53
View file @
333fc034
...
...
@@ -53,7 +53,6 @@ extern "C" {
static
const
char
*
tuplelib_name
=
"box.tuple"
;
static
const
char
*
tuple_iteratorlib_name
=
"box.tuple.iterator"
;
static
int
tuple_totable_mt_ref
=
0
;
/* a precreated metable for totable() */
extern
char
tuple_lua
[];
/* Lua source */
...
...
@@ -375,48 +374,6 @@ lbox_tuple_findall(struct lua_State *L)
return
lbox_tuple_find_do
(
L
,
true
);
}
static
int
lbox_tuple_unpack
(
struct
lua_State
*
L
)
{
int
argc
=
lua_gettop
(
L
);
(
void
)
argc
;
struct
tuple
*
tuple
=
lua_checktuple
(
L
,
1
);
struct
tuple_iterator
it
;
tuple_rewind
(
&
it
,
tuple
);
const
char
*
field
;
while
((
field
=
tuple_next
(
&
it
)))
luamp_decode
(
L
,
&
field
);
assert
(
lua_gettop
(
L
)
==
argc
+
tuple_arity
(
tuple
));
(
void
)
argc
;
return
tuple_arity
(
tuple
);
}
static
int
lbox_tuple_totable
(
struct
lua_State
*
L
)
{
struct
tuple
*
tuple
=
lua_checktuple
(
L
,
1
);
lua_newtable
(
L
);
int
index
=
1
;
struct
tuple_iterator
it
;
tuple_rewind
(
&
it
,
tuple
);
const
char
*
field
;
while
((
field
=
tuple_next
(
&
it
)))
{
lua_pushnumber
(
L
,
index
++
);
luamp_decode
(
L
,
&
field
);
lua_rawset
(
L
,
-
3
);
}
/* Hint serializer */
assert
(
tuple_totable_mt_ref
!=
0
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
tuple_totable_mt_ref
);
lua_setmetatable
(
L
,
-
2
);
return
1
;
}
void
lbox_pushtuple
(
struct
lua_State
*
L
,
struct
tuple
*
tuple
)
{
...
...
@@ -439,8 +396,6 @@ static const struct luaL_reg lbox_tuple_meta[] = {
{
"transform"
,
lbox_tuple_transform
},
{
"find"
,
lbox_tuple_find
},
{
"findall"
,
lbox_tuple_findall
},
{
"unpack"
,
lbox_tuple_unpack
},
{
"totable"
,
lbox_tuple_totable
},
{
NULL
,
NULL
}
};
...
...
@@ -490,14 +445,6 @@ box_lua_tuple_init(struct lua_State *L)
luamp_set_encode_extension
(
luamp_encode_extension_box
);
/* Precreate a metatable for tuple_unpack */
lua_newtable
(
L
);
lua_pushstring
(
L
,
"_serializer_compact"
);
lua_pushboolean
(
L
,
true
);
lua_settable
(
L
,
-
3
);
tuple_totable_mt_ref
=
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
assert
(
tuple_totable_mt_ref
!=
0
);
if
(
luaL_dostring
(
L
,
tuple_lua
))
panic
(
"Error loading Lua source %.160s...: %s"
,
tuple_lua
,
lua_tostring
(
L
,
-
1
));
...
...
This diff is collapsed.
Click to expand it.
src/box/lua/tuple.lua
+
26
−
2
View file @
333fc034
...
...
@@ -81,6 +81,30 @@ local function tuple_ipairs(tuple, pos)
return
it
,
tuple
,
pos
end
-- a precreated metatable for totable()
local
tuple_totable_mt
=
{
_serializer_compact
=
true
;
}
local
function
tuple_totable
(
tuple
)
-- use a precreated iterator for tuple_next
builtin
.
tuple_rewind
(
next_it
,
tuple
)
local
ret
=
{}
while
true
do
local
field
=
builtin
.
tuple_next
(
next_it
)
if
field
==
nil
then
break
end
local
val
=
msgpackffi
.
decode_unchecked
(
field
)
table.insert
(
ret
,
val
)
end
return
setmetatable
(
ret
,
tuple_totable_mt
)
end
local
function
tuple_unpack
(
tuple
)
return
unpack
(
tuple_totable
(
tuple
))
end
-- cfuncs table is set by C part
local
methods
=
{
...
...
@@ -91,8 +115,8 @@ local methods = {
[
"transform"
]
=
cfuncs
.
transform
;
[
"find"
]
=
cfuncs
.
find
;
[
"findall"
]
=
cfuncs
.
findall
;
[
"unpack"
]
=
cfuncs
.
unpack
;
[
"totable"
]
=
cfuncs
.
totable
;
[
"unpack"
]
=
tuple_
unpack
;
[
"totable"
]
=
tuple_
totable
;
[
"bsize"
]
=
function
(
tuple
)
return
tonumber
(
tuple
.
_bsize
)
end
...
...
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