Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
appwilldev
luascws
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
luascws
/
scws.lua
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
69 lines (59 loc) · 1.33 KB
master
Breadcrumbs
luascws
/
scws.lua
Copy path
Top
File metadata and controls
Code
Blame
69 lines (59 loc) · 1.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env luajit
local ffi = require("ffi")
local io_open = io.open
local setmetatable = setmetatable
local error = error
local t_insert = table.insert
local strsub = string.sub
require('scws_header')
-- debug
local print = print
module("scws")
local scws = {}
scws.XDICT_XDB = 1
scws.XDICT_MEM = 2
scws.XDICT_TXT = 4
local S = ffi.load('scws')
function scws:new(dict, rules, charset, dicttype)
local o = {}
if not charset then
charset = 'utf-8'
end
if not dicttype then
dicttype = scws.XDICT_XDB
end
local s = ffi.gc(S.scws_new(), S.scws_free)
S.scws_set_charset(s, charset)
local st = S.scws_set_dict(s, dict, dicttype)
if st < 0 then
error('failed to set dict')
end
if rules then
S.scws_set_rule(s, rules)
end
o._scws = s
setmetatable(o, self)
self.__index = self
return o
end
function scws:__call(sentence)
local s = self._scws
if not s then
error("can't find myself, sorry.")
end
S.scws_send_text(s, sentence, #sentence);
local ret = {}
while true do
local result = S.scws_get_result(s)
if result == nil then break end
local cursor = result
while cursor ~= nil do
local o = strsub(sentence, cursor.off+1, cursor.off + cursor.len)
t_insert(ret, o)
cursor = cursor.next
end
S.scws_free_result(result)
end
return ret
end
return scws
You can’t perform that action at this time.