Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tales of MajEyal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
yutio888
Tales of MajEyal
Commits
670702a6
Commit
670702a6
authored
14 years ago
by
dg
Browse files
Options
Downloads
Patches
Plain Diff
plop
git-svn-id:
http://svn.net-core.org/repos/t-engine4@2070
51575b47-30f0-44d4-a5cc-537603b46e54
parent
262b3c67
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
game/engines/default/engine/class.lua
+13
-1
13 additions, 1 deletion
game/engines/default/engine/class.lua
src/serial.c
+47
-15
47 additions, 15 deletions
src/serial.c
with
60 additions
and
16 deletions
game/engines/default/engine/class.lua
+
13
−
1
View file @
670702a6
...
...
@@ -118,7 +118,8 @@ local function clonerecursfull(clonetable, d)
local
n
=
{}
clonetable
[
d
]
=
n
for
k
,
e
in
pairs
(
d
)
do
local
k
,
e
=
next
(
d
)
while
k
do
local
nk
,
ne
=
k
,
e
if
clonetable
[
k
]
then
nk
=
clonetable
[
k
]
elseif
type
(
k
)
==
"table"
then
nk
,
add
=
clonerecursfull
(
clonetable
,
k
)
nb
=
nb
+
add
...
...
@@ -128,6 +129,8 @@ local function clonerecursfull(clonetable, d)
elseif
type
(
e
)
==
"table"
and
(
type
(
k
)
~=
"string"
or
k
~=
"__threads"
)
then
ne
,
add
=
clonerecursfull
(
clonetable
,
e
)
nb
=
nb
+
add
end
n
[
nk
]
=
ne
k
,
e
=
next
(
d
,
k
)
end
setmetatable
(
n
,
getmetatable
(
d
))
if
n
.
cloned
and
n
.
__CLASSNAME
then
n
:
cloned
(
d
)
end
...
...
@@ -138,6 +141,15 @@ end
--- Clones the object, all subobjects without cloning twice a subobject
-- @return the clone and the number of cloned objects
function
_M
:
cloneFull
()
-- local old = core.game.getTime()
-- core.serial.cloneFull(self)
-- print("CLONE C", core.game.getTime() - old)
-- old = core.game.getTime()
-- local clonetable = {}
-- clonerecursfull(clonetable, self)
-- print("CLONE LUA", core.game.getTime() - old)
local
clonetable
=
{}
return
clonerecursfull
(
clonetable
,
self
)
-- return core.serial.cloneFull(self)
...
...
This diff is collapsed.
Click to expand it.
src/serial.c
+
47
−
15
View file @
670702a6
...
...
@@ -270,17 +270,13 @@ static int serial_tozip(lua_State *L)
}
#define CLONETABLE 2
#define CLONETABLE_LIST 3
static
int
serial_clonefull_recurs
(
lua_State
*
L
,
int
idx
)
{
int
ktype
,
etype
;
int
nb
=
0
;
lua_newtable
(
L
);
// Store in the clonetable
lua_pushvalue
(
L
,
idx
-
1
);
lua_pushvalue
(
L
,
-
2
);
lua_rawset
(
L
,
CLONETABLE
);
// We are called with the newtable on top of the stack
lua_pushnil
(
L
);
/* first key */
while
(
lua_next
(
L
,
idx
-
2
)
!=
0
)
...
...
@@ -303,12 +299,20 @@ static int serial_clonefull_recurs(lua_State *L, int idx)
{
// Check clonetable first
lua_pushvalue
(
L
,
-
2
);
lua_get
table
(
L
,
CLONETABLE
);
lua_
raw
get
(
L
,
CLONETABLE
);
if
(
lua_isnil
(
L
,
-
1
))
{
// If not found, clone it
lua_pop
(
L
,
1
);
nb
+=
serial_clonefull_recurs
(
L
,
-
2
);
lua_newtable
(
L
);
// Store in the clonetable
lua_pushvalue
(
L
,
-
3
);
lua_pushvalue
(
L
,
-
2
);
lua_rawset
(
L
,
CLONETABLE
);
lua_pushvalue
(
L
,
-
3
);
lua_pushvalue
(
L
,
-
2
);
lua_rawset
(
L
,
CLONETABLE_LIST
);
}
}
else
...
...
@@ -320,12 +324,20 @@ static int serial_clonefull_recurs(lua_State *L, int idx)
{
// Check clonetable first
lua_pushvalue
(
L
,
-
2
);
lua_get
table
(
L
,
CLONETABLE
);
lua_
raw
get
(
L
,
CLONETABLE
);
if
(
lua_isnil
(
L
,
-
1
))
{
// If not found, clone it
lua_pop
(
L
,
1
);
nb
+=
serial_clonefull_recurs
(
L
,
-
2
);
lua_newtable
(
L
);
// Store in the clonetable
lua_pushvalue
(
L
,
-
3
);
lua_pushvalue
(
L
,
-
2
);
lua_rawset
(
L
,
CLONETABLE
);
lua_pushvalue
(
L
,
-
3
);
lua_pushvalue
(
L
,
-
2
);
lua_rawset
(
L
,
CLONETABLE_LIST
);
}
}
else
...
...
@@ -371,15 +383,35 @@ static int serial_clonefull_recurs(lua_State *L, int idx)
static
int
serial_clonefull
(
lua_State
*
L
)
{
luaL_checktype
(
L
,
1
,
LUA_TTABLE
);
lua_newtable
(
L
);
// idx 2 == clonetable
printf
(
"<TOP %d
\n
"
,
lua_gettop
(
L
));
lua_newtable
(
L
);
// idx 2 == clonetable_all
lua_newtable
(
L
);
// idx 3 == clonetable
// Store in the clonetable
lua_pushvalue
(
L
,
1
);
lua_newtable
(
L
);
lua_rawset
(
L
,
CLONETABLE
);
lua_pushvalue
(
L
,
1
);
int
nb
=
serial_clonefull_recurs
(
L
,
-
1
);
lua_newtable
(
L
);
lua_rawset
(
L
,
CLONETABLE_LIST
);
int
nb
=
0
;
lua_pushnil
(
L
);
/* first key */
while
(
lua_next
(
L
,
CLONETABLE_LIST
)
!=
0
)
{
// printf("<TOP %d\n", lua_gettop(L));
nb
+=
serial_clonefull_recurs
(
L
,
-
1
);
// printf(">TOP %d // %d\n", lua_gettop(L), nb);
// Remove from list
lua_pop
(
L
,
1
);
// remove value
lua_pushnil
(
L
);
// set to nil
lua_rawset
(
L
,
CLONETABLE_LIST
);
// Reset the next()
lua_pushnil
(
L
);
}
lua_pushnumber
(
L
,
nb
);
printf
(
">TOP %d
\n
"
,
lua_gettop
(
L
));
return
2
;
}
...
...
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