@@ -378,7 +378,7 @@ API.coroutine = {}
378
378
local ABORT_ERROR = {
379
379
msg = " browser is no longer waiting for list - aborting parse"
380
380
}
381
- local newindex = function (t , k , v ) error ((" attempted to assign `%s` to key `%s` in read-only %s" ):format (v , k , t ), 2 ) end
381
+ local readonly_newindex = function (t , k , v ) error ((" attempted to assign `%s` to key `%s` in read-only %s" ):format (v , k , t ), 2 ) end
382
382
383
383
-- implements table.pack if on lua 5.1
384
384
if not table.pack then
730
730
if references [t ] then return references [t ] end
731
731
732
732
local ro = setmetatable ({}, {
733
- __newindex = newindex ,
733
+ __newindex = readonly_newindex ,
734
734
mutable = t ,
735
735
__index = function (_ , k )
736
736
return API .read_only ( t [k ] )
743
743
end
744
744
end
745
745
746
+ -- returns read-only references to all given values
747
+ function API .read_only_values (...)
748
+ local vals = table.pack (... )
749
+ for i , v in ipairs (vals ) do vals [i ] = API .read_only (v ) end
750
+ return table.unpack (vals )
751
+ end
752
+
753
+ -- returns true if the given tale is read-only
754
+ function API .is_read_only (t )
755
+ local mt = getmetatable (t )
756
+ return mt and mt .__newindex == readonly_newindex
757
+ end
758
+
746
759
747
760
748
761
---- ----------------------------------------------------------------------------------------------------
@@ -1042,7 +1055,7 @@ end
1042
1055
-- select all items in the list
1043
1056
local function select_all ()
1044
1057
local selection = {}
1045
- for i , _ in ipairs (state .list ) do
1058
+ for i in ipairs (state .list ) do
1046
1059
selection [i ] = true
1047
1060
end
1048
1061
0 commit comments