Skip to content

Commit 08e767b

Browse files
authored
Merge pull request yuin#302 from KevinCaiqimin/master
fix like "00" will be paused 12, and check nil val of os.time like os…
2 parents af7e27f + 82b346b commit 08e767b

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

oslib.go

+24-13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func getIntField(L *LState, tb *LTable, key string, v int) int {
2525
if strings.HasPrefix(slv, "0") && !strings.HasPrefix(slv, "0x") && !strings.HasPrefix(slv, "0X") {
2626
//Standard lua interpreter only support decimal and hexadecimal
2727
slv = strings.TrimLeft(slv, "0")
28+
if slv == "" {
29+
return 0
30+
}
2831
}
2932
if num, err := parseNumber(slv); err == nil {
3033
return int(num)
@@ -189,20 +192,28 @@ func osTime(L *LState) int {
189192
if L.GetTop() == 0 {
190193
L.Push(LNumber(time.Now().Unix()))
191194
} 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()))
204216
}
205-
L.Push(LNumber(t.Unix()))
206217
}
207218
return 1
208219
}

0 commit comments

Comments
 (0)