From 1c52c658722148022a0dad047e447d7af847b4f4 Mon Sep 17 00:00:00 2001 From: Meo597 <197331664+Meo597@users.noreply.github.com> Date: Mon, 28 Sep 2026 22:52:45 +0800 Subject: [PATCH] geodata: rename Lua matcher constructors to BuildDomainMatcher and BuildIPMatcher --- app/dns/lua_test.go | 2 +- app/dns/script_test.go | 2 +- common/geodata/lua.go | 4 ++-- common/geodata/lua_test.go | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/dns/lua_test.go b/app/dns/lua_test.go index 3fb089616..a9ace300f 100644 --- a/app/dns/lua_test.go +++ b/app/dns/lua_test.go @@ -158,7 +158,7 @@ func TestLuaDNSServerQuery(t *testing.T) { server.RegisterLua(L) if err := L.DoString(` local server = require("xray.dns").Servers[1] -local matcher = require("xray.geodata").IPMatcher("127.0.0.0/8") +local matcher = require("xray.geodata").BuildIPMatcher("127.0.0.0/8") function HandleDNSQuery(domain, ipv4, ipv6, fake) local ips, ttl, err = server:Query(domain, ipv4, ipv6, fake) assert(type(ips) == "userdata" and not err) diff --git a/app/dns/script_test.go b/app/dns/script_test.go index efeffedbf..4ddcf8ef5 100644 --- a/app/dns/script_test.go +++ b/app/dns/script_test.go @@ -38,7 +38,7 @@ func TestDNSScriptGeoIPFallback(t *testing.T) { t.Setenv("xray.location.asset", filepath.Join("..", "..", "resources")) script := ` local servers = require("xray.dns").Servers -local us_ips = require("xray.geodata").IPMatcher("geoip:us") +local us_ips = require("xray.geodata").BuildIPMatcher("geoip:us") local by_id = {} for _, server in ipairs(servers) do diff --git a/common/geodata/lua.go b/common/geodata/lua.go index 84324c3f4..a93a4b7b5 100644 --- a/common/geodata/lua.go +++ b/common/geodata/lua.go @@ -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("BuildDomainMatcher", 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("BuildIPMatcher", L.NewFunction(func(L *lua.LState) int { parsed, err := ParseIPRules(luaRules(L)) if err != nil { L.RaiseError("%v", err) diff --git a/common/geodata/lua_test.go b/common/geodata/lua_test.go index 6004369a2..dbc232e5e 100644 --- a/common/geodata/lua_test.go +++ b/common/geodata/lua_test.go @@ -18,7 +18,7 @@ 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") + local matcher = require("xray.geodata").BuildIPMatcher("127.0.0.0/8", "::1") assert(matcher:Match(ip)) assert(matcher:AnyMatch(ips)) assert(not matcher:Matches(ips)) @@ -35,7 +35,7 @@ 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") + local matcher = require("xray.geodata").BuildDomainMatcher("example.com", "full:other.com") assert(matcher:MatchAny("example.com")) assert(matcher:MatchAny("www.example.com")) assert(matcher:MatchAny("other.com")) @@ -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").BuildIPMatcher("not-an-ip")`}, + {"non-string domain rule", `require("xray.geodata").BuildDomainMatcher("example.com", true)`}, } { t.Run(tc.name, func(t *testing.T) { L := lua.NewState()