Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tales of MajEyal
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
tome
Tales of MajEyal
Commits
6f43ddef
Commit
6f43ddef
authored
11 years ago
by
DarkGod
Browse files
Options
Downloads
Patches
Plain Diff
use faster serialization
parent
926f57fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
game/loader/pre-init.lua
+55
-22
55 additions, 22 deletions
game/loader/pre-init.lua
with
55 additions
and
22 deletions
game/loader/pre-init.lua
+
55
−
22
View file @
6f43ddef
...
...
@@ -83,38 +83,71 @@ end
--- This is a really naive algorithm, it will not handle objects and such.
-- Use only for small tables
function
table
.
serialize
(
src
,
sub
,
no_G
,
base
)
local
str
=
""
if
sub
then
str
=
"{"
end
local
chunks
=
{}
if
sub
then
chunks
[
1
]
=
"{"
end
for
k
,
e
in
pairs
(
src
)
do
local
nk
,
ne
=
k
,
e
local
nk
=
nil
local
nkC
=
{}
local
tk
,
te
=
type
(
k
),
type
(
e
)
if
no_G
then
if
tk
==
"table"
then
nk
=
"["
..
table
.
serialize
(
nk
,
true
)
..
"]"
elseif
tk
==
"string"
then
-- nothing
else
nk
=
"["
..
nk
..
"]"
if
tk
==
"table"
then
nkC
[
#
nkC
+
1
]
=
"["
nkC
[
#
nkC
+
1
]
=
table
.
serialize
(
k
,
true
)
nkC
[
#
nkC
+
1
]
=
"]"
elseif
tk
==
"string"
then
nkC
[
#
nkC
+
1
]
=
k
else
nkC
[
#
nkC
+
1
]
=
"["
nkC
[
#
nkC
+
1
]
=
tostring
(
k
)
nkC
[
#
nkC
+
1
]
=
"]"
end
else
if
tk
==
"table"
then
nk
=
"["
..
table
.
serialize
(
nk
,
true
)
..
"]"
elseif
tk
==
"string"
then
nk
=
string.format
(
"[%q]"
,
nk
)
else
nk
=
"["
..
nk
..
"]"
if
not
sub
then
nkC
[
#
nkC
+
1
]
=
(
base
and
tostring
(
base
)
or
"_G"
)
end
nkC
[
#
nkC
+
1
]
=
"["
if
tk
==
"table"
then
nkC
[
#
nkC
+
1
]
=
table
.
serialize
(
k
,
true
)
elseif
tk
==
"string"
then
-- escaped quotes matter
nkC
[
#
nkC
+
1
]
=
string.format
(
"%q"
,
k
)
else
nkC
[
#
nkC
+
1
]
=
tostring
(
k
)
end
if
not
sub
then
nk
=
(
base
or
"_G"
)
..
nk
end
nkC
[
#
nkC
+
1
]
=
"]"
end
if
te
==
"table"
then
str
=
str
..
string.format
(
"%s=%s "
,
nk
,
table
.
serialize
(
ne
,
true
))
elseif
te
==
"number"
then
str
=
str
..
string.format
(
"%s=%f "
,
nk
,
ne
)
elseif
te
==
"string"
then
str
=
str
..
string.format
(
"%s=%q "
,
nk
,
ne
)
elseif
te
==
"boolean"
then
str
=
str
..
string.format
(
"%s=%s "
,
nk
,
tostring
(
ne
))
nk
=
table.concat
(
nkC
)
-- These are the types of data we are willing to serialize
if
te
==
"table"
or
te
==
"string"
or
te
==
"number"
or
te
==
"boolean"
then
chunks
[
#
chunks
+
1
]
=
nk
chunks
[
#
chunks
+
1
]
=
"="
if
te
==
"table"
then
chunks
[
#
chunks
+
1
]
=
table
.
serialize
(
e
,
true
)
elseif
te
==
"number"
then
-- float output matters
chunks
[
#
chunks
+
1
]
=
string.format
(
"%f"
,
e
)
elseif
te
==
"string"
then
-- escaped quotes matter
chunks
[
#
chunks
+
1
]
=
string.format
(
"%q"
,
e
)
else
-- te == "boolean"
chunks
[
#
chunks
+
1
]
=
tostring
(
e
)
end
chunks
[
#
chunks
+
1
]
=
" "
end
if
sub
then
chunks
[
#
chunks
+
1
]
=
", "
end
if
sub
then
str
=
str
..
", "
end
end
if
sub
then
str
=
str
..
"}"
end
return
str
if
sub
then
chunks
[
#
chunks
+
1
]
=
"}"
end
return
table.concat
(
chunks
)
end
function
string
.
unserialize
(
str
)
...
...
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