Skip to content

Commit 09230a8

Browse files
committed
Update DataTableOptimizer.lua
add better error report when create default values failed
1 parent 78a083f commit 09230a8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

DataTableOptimizer.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--[[
22
How to use:
33
4-
Put all lua files into DatabaseRoot then call ExportDatabaseLocalText( tofile = true, newStringBank = false ) ( beware: all your original files will be replaced with optimized files )
4+
Put all lua files into DatabaseRoot then call ExportDatabaseLocalText( tofile = true, newStringBank = false ) at the end of file. ( beware: all your original files will be replaced with optimized files )
55
If you want to exlucde some input files in DatabaseRoot, just add theirs names into ExcludedFiles
66
77
@@ -35,7 +35,7 @@ local StringBankCSVOutput = DatabaseRoot.."/"..DatabaseLocaleTextName..".csv"
3535
local MaxStringBankRedundancy = 100
3636
local MaxStringBankBinSize = 524288
3737
local LocaleTextLeadingTag = '@'
38-
local MaxLocalVariableNum = 190 -- lparser.c #define MAXVARS 200
38+
local MaxLocalVariableNum = 160 -- lparser.c #define MAXVARS 200
3939
local RefTableName = "__rt"
4040
local DefaultValueTableName = "__default_values"
4141
local PrintTableRefCount = false
@@ -161,8 +161,11 @@ local function OrderedForeachByValue( _table, _func )
161161
for _, _v in ipairs( kv ) do
162162
local k = _v[ 1 ]
163163
local v = _v[ 2 ]
164-
_func( k, v )
164+
if not pcall( _func, k, v ) then
165+
return false
166+
end
165167
end
168+
return true
166169
end
167170
end
168171

@@ -1119,7 +1122,7 @@ local function OptimizeDataset( dataset )
11191122
local max = -1
11201123
local defaultValue = nil
11211124
local _defaultValue = "{}"
1122-
OrderedForeachByValue(
1125+
local result = OrderedForeachByValue(
11231126
defaultValueStat,
11241127
function( value, count )
11251128
if count >= max then
@@ -1150,6 +1153,9 @@ local function OptimizeDataset( dataset )
11501153
end
11511154
end
11521155
)
1156+
if not result then
1157+
error( string.format( "create default value for \"%s\" failed. please make sure all the value's types are the same.", field ) )
1158+
end
11531159
if defaultValue ~= nil then
11541160
defaultValues = defaultValues or {}
11551161
defaultValues[ field ] = defaultValue

0 commit comments

Comments
 (0)