forked from lua-stdlib/lua-stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrbuf.lua
More file actions
79 lines (65 loc) · 1.79 KB
/
strbuf.lua
File metadata and controls
79 lines (65 loc) · 1.79 KB
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
70
71
72
73
74
75
76
77
78
79
--[[--
String buffers.
Prototype Chain
---------------
table
`-> Object
`-> StrBuf
@classmod std.strbuf
]]
local base = require "std.base"
local Object = require "std.object" {}
local function X (decl, fn)
return require "std.debug".argscheck ("std.strbuf." .. decl, fn)
end
--- StrBuf prototype object.
--
-- Set also inherits all the fields and methods from
-- @{std.object.Object}.
-- @object StrBuf
-- @string[opt="StrBuf"] _type object name
-- @see std.object.__call
-- @usage
-- local std = require "std"
-- local StrBuf = std.strbuf {}
-- local buf = StrBuf {"initial buffer contents"}
-- buf = buf .. "append to buffer"
-- print (buf) -- implicit `tostring` concatenates everything
-- os.exit (0)
return Object {
_type = "StrBuf",
--- Support concatenation to StrBuf objects.
-- @function __concat
-- @tparam StrBuf buffer object
-- @string s a string
-- @treturn StrBuf modified *buf*
-- @see concat
-- @usage
-- buf = buf .. str
__concat = X ("__concat (StrBuf, string)", base.insert),
--- Support fast conversion to Lua string.
-- @function __tostring
-- @tparam StrBuf buffer object
-- @treturn string concatenation of buffer contents
-- @see tostring
-- @usage
-- str = tostring (buf)
__tostring = X ("__tostring (StrBuf)", table.concat),
__index = {
--- Add a string to a buffer.
-- @static
-- @function concat
-- @string s string to add
-- @treturn StrBuf modified buffer
-- @usage
-- buf = concat (buf, "append this")
concat = X ("concat (StrBuf, string)", base.insert),
--- Convert a buffer to a string.
-- @static
-- @function tostring
-- @treturn string stringified `buf`
-- @usage
-- string = buf:tostring ()
tostring = X ("tostring (StrBuf)", table.concat),
},
}