lua: standardize hooks and host APIs on PascalCase

This commit is contained in:
Meo597
2026-09-28 22:52:14 +08:00
parent 3d3306503d
commit 5724db08f4
9 changed files with 66 additions and 66 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ func RegisterLua(L *lua.LState) {
L.PreloadModule("xray.geodata", func(L *lua.LState) int {
module := L.NewTable()
module.RawSetString("domainMatcher", L.NewFunction(func(L *lua.LState) int {
module.RawSetString("DomainMatcher", L.NewFunction(func(L *lua.LState) int {
parsed, err := ParseDomainRules(luaRules(L), Domain_Domain)
if err != nil {
L.RaiseError("%v", err)
@@ -25,7 +25,7 @@ func RegisterLua(L *lua.LState) {
return 1
}))
module.RawSetString("ipMatcher", L.NewFunction(func(L *lua.LState) int {
module.RawSetString("IPMatcher", L.NewFunction(func(L *lua.LState) int {
parsed, err := ParseIPRules(luaRules(L))
if err != nil {
L.RaiseError("%v", err)
+13 -13
View File
@@ -18,11 +18,11 @@ func TestLuaIPMatcher(t *testing.T) {
ips.Value = []net.IP{ip.Value.(net.IP), net.ParseIP("8.8.8.8")}
L.SetGlobal("ips", ips)
if err := L.DoString(`
local matcher = require("xray.geodata").ipMatcher("127.0.0.0/8", "::1")
assert(matcher:match(ip))
assert(matcher:anyMatch(ips))
assert(not matcher:matches(ips))
local matched, unmatched = matcher:filterIPs(ips)
local matcher = require("xray.geodata").IPMatcher("127.0.0.0/8", "::1")
assert(matcher:Match(ip))
assert(matcher:AnyMatch(ips))
assert(not matcher:Matches(ips))
local matched, unmatched = matcher:FilterIPs(ips)
assert(type(matched) == "userdata" and type(unmatched) == "userdata")
assert(#matched == 1 and #unmatched == 1)
`); err != nil {
@@ -35,12 +35,12 @@ func TestLuaDomainMatcher(t *testing.T) {
defer L.Close()
RegisterLua(L)
if err := L.DoString(`
local matcher = require("xray.geodata").domainMatcher("example.com", "full:other.com")
assert(matcher:matchAny("example.com"))
assert(matcher:matchAny("www.example.com"))
assert(matcher:matchAny("other.com"))
assert(not matcher:matchAny("www.other.com"))
assert(#(matcher:match("www.example.com")) == 1)
local matcher = require("xray.geodata").DomainMatcher("example.com", "full:other.com")
assert(matcher:MatchAny("example.com"))
assert(matcher:MatchAny("www.example.com"))
assert(matcher:MatchAny("other.com"))
assert(not matcher:MatchAny("www.other.com"))
assert(#(matcher:Match("www.example.com")) == 1)
`); err != nil {
t.Fatal(err)
}
@@ -51,8 +51,8 @@ func TestLuaMatchersRejectInvalidRules(t *testing.T) {
name string
script string
}{
{"IP rule", `require("xray.geodata").ipMatcher("not-an-ip")`},
{"non-string domain rule", `require("xray.geodata").domainMatcher("example.com", true)`},
{"IP rule", `require("xray.geodata").IPMatcher("not-an-ip")`},
{"non-string domain rule", `require("xray.geodata").DomainMatcher("example.com", true)`},
} {
t.Run(tc.name, func(t *testing.T) {
L := lua.NewState()