@@ -25,6 +25,9 @@ func getIntField(L *LState, tb *LTable, key string, v int) int {
25
25
if strings .HasPrefix (slv , "0" ) && ! strings .HasPrefix (slv , "0x" ) && ! strings .HasPrefix (slv , "0X" ) {
26
26
//Standard lua interpreter only support decimal and hexadecimal
27
27
slv = strings .TrimLeft (slv , "0" )
28
+ if slv == "" {
29
+ return 0
30
+ }
28
31
}
29
32
if num , err := parseNumber (slv ); err == nil {
30
33
return int (num )
@@ -189,20 +192,28 @@ func osTime(L *LState) int {
189
192
if L .GetTop () == 0 {
190
193
L .Push (LNumber (time .Now ().Unix ()))
191
194
} else {
192
- tbl := L .CheckTable (1 )
193
- sec := getIntField (L , tbl , "sec" , 0 )
194
- min := getIntField (L , tbl , "min" , 0 )
195
- hour := getIntField (L , tbl , "hour" , 12 )
196
- day := getIntField (L , tbl , "day" , - 1 )
197
- month := getIntField (L , tbl , "month" , - 1 )
198
- year := getIntField (L , tbl , "year" , - 1 )
199
- isdst := getBoolField (L , tbl , "isdst" , false )
200
- t := time .Date (year , time .Month (month ), day , hour , min , sec , 0 , time .Local )
201
- // TODO dst
202
- if false {
203
- print (isdst )
195
+ lv := L .CheckAny (1 )
196
+ if lv == LNil {
197
+ L .Push (LNumber (time .Now ().Unix ()))
198
+ } else {
199
+ tbl , ok := lv .(* LTable )
200
+ if ! ok {
201
+ L .TypeError (1 , LTTable )
202
+ }
203
+ sec := getIntField (L , tbl , "sec" , 0 )
204
+ min := getIntField (L , tbl , "min" , 0 )
205
+ hour := getIntField (L , tbl , "hour" , 12 )
206
+ day := getIntField (L , tbl , "day" , - 1 )
207
+ month := getIntField (L , tbl , "month" , - 1 )
208
+ year := getIntField (L , tbl , "year" , - 1 )
209
+ isdst := getBoolField (L , tbl , "isdst" , false )
210
+ t := time .Date (year , time .Month (month ), day , hour , min , sec , 0 , time .Local )
211
+ // TODO dst
212
+ if false {
213
+ print (isdst )
214
+ }
215
+ L .Push (LNumber (t .Unix ()))
204
216
}
205
- L .Push (LNumber (t .Unix ()))
206
217
}
207
218
return 1
208
219
}
0 commit comments