Название: Monitor or script looping problem
Отправлено: truefriend-cz от 31 июля 2017, 16:11:19
Hi. I create script, but ended looping. Do you can help me where is bad? --[[ <HCExtension> @name Test @author truefriend-cz @version Beta @event BeforeViewInMonitor @event RequestHeaderReceived @event AnswerHeaderReceived @event BeforeAnswerHeaderSend </HCExtension> ]]
function BeforeViewInMonitor() monitor_string = '' monitor_string_array = {} end
function RequestHeaderReceived() if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array, 1, 'Load from Cache') else hc.action = 'save' table.insert(monitor_string_array, 1, 'Saved to Cache') end end
function AnswerHeaderReceived() table.insert(monitor_string_array, 2, '(Test)') end
function BeforeAnswerHeaderSend() for string_number, string_text in ipairs(monitor_string_array) do monitor_string = monitor_string..string_text end hc.monitor_string = monitor_string end
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 31 июля 2017, 21:42:32
This problem have if Saving only. If Load from Cache then monitor text one normal.
Название: Re: Monitor or script looping problem
Отправлено: Михаил от 31 июля 2017, 23:34:28
Pipelining can make influence. Try to test this extension with disabled pipelining feature in browser.
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 01 августа 2017, 02:01:36
Yes. It is solved. Thank you very much. Do you know any solution for restriction on HC side for block Pipelining from clients? Or do you know what use for this feature from commands of LUA (for block Pipelining from clients)? Pipelining can make influence. Try to test this extension with disabled pipelining feature in browser.
Название: Re: Monitor or script looping problem
Отправлено: Михаил от 01 августа 2017, 08:01:54
Do you know any solution for restriction on HC side for block Pipelining from clients? Or do you know what use for this feature from commands of LUA (for block Pipelining from clients)?
I think it's a bad idea to block pipelining. You can modify your code to work well with pipelined requests instead. --[[ <HCExtension> @name Test2 @author truefriend-cz @version Beta @event RequestHeaderReceived @event AnswerHeaderReceived @event BeforeAnswerHeaderSend </HCExtension> ]]
function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' monitor_string_array[hc.monitor_index] = 'Load from Cache' else hc.action = 'save' monitor_string_array[hc.monitor_index] = 'Save to Cache' end end
function AnswerHeaderReceived() monitor_string_array[hc.monitor_index] = monitor_string_array[hc.monitor_index] .. '(Test)' end
function BeforeAnswerHeaderSend() hc.monitor_string = monitor_string_array[hc.monitor_index] end
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 01 августа 2017, 09:45:35
Yes, its better. But freezing random connections (image2.png) and after one-two min.s, ended error "Freezing connection". But is better - HandyCache no shut down, or CPU HC process no overheat. I using after this sorting, etc.. where table number is priority position for Monitor... --[[ <HCExtension> @name Test 3 @author truefriend-cz @version Beta @event BeforeViewInMonitor @event RequestHeaderReceived @event BeforeAnswerHeaderSend </HCExtension> ]]
function monitor_add_string(d) if check_empty(monitor_string) then return d else return delimiter..d end end
function monitor_show() if check_full(monitor_string) then hc.monitor_string = monitor_string end if check_full(monitor_color) then hc.monitor_text_color = monitor_color end end
function check_empty(d) return d == '' or d == nil end
function check_full(e) return e ~= '' or e ~= nil end
function sort_table(t, f) local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0 local iter = function() i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter end
function BeforeViewInMonitor() monitor_string = '' monitor_string_array = {} delimiter = ' - ||| - ' end
function RequestHeaderReceived() if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array, 10, 'Load from Cache') else hc.action = 'save' table.insert(monitor_string_array, 11, 'Saved to Cache') end end
function BeforeAnswerHeaderSend() table.insert(monitor_string_array, 40, '(Test priority 2)') table.insert(monitor_string_array, 17, '(Test priority 1)') table.insert(monitor_string_array, 55, '(Test priority 4)') table.insert(monitor_string_array, 53, '(Test priority 3)')
for string_number, string_text in sort_table(monitor_string_array) do monitor_string = monitor_string..monitor_add_string(string_text) end monitor_show() end I can monitor_string_array[hc.monitor_index] sorting?
Название: Re: Monitor or script looping problem
Отправлено: Михаил от 01 августа 2017, 10:09:14
Yes, its better. But freezing random connections (image2.png) and after one-two min.s, ended error "Freezing connection".
Are your shure that my example extension freezez HC? I see no code to freeze HC in it. I can monitor_string_array[hc.monitor_index] sorting? I using after this sorting, etc.. where table number is priority position for Monitor... Sorry but I don't understand what Test 3 extension is for. Can you describe your aims in another words?
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 01 августа 2017, 10:17:00
I'm trying to put my own separator into the Monitor and sort the strings by the manual priority label because it comes from other LUA Extension files (it does not always come automatically in the order I want).
Pipelining: Your solution is better for optimized pipelining. Lines where before script Test 1 cycled lines in script Test 2 changed to (Image3.png)
Название: Re: Monitor or script looping problem
Отправлено: Михаил от 01 августа 2017, 11:45:38
I'm trying to put my own separator into the Monitor and sort the strings by the manual priority label because it comes from other LUA Extension files (it does not always come automatically in the order I want).
In Test3 you ignore pipelining issue again. May be you need something like this: --[[ <HCExtension> @name Test4 @author truefriend-cz @version Beta @event RequestHeaderReceived @event BeforeAnswerHeaderSend </HCExtension> ]]
function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} monitor_string_array[hc.monitor_index] = {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array[hc.monitor_index], {priority=10, text='Load from Cache'}) else hc.action = 'save' table.insert(monitor_string_array[hc.monitor_index], {priority=11, text='Saved to Cache'}) end end
function BeforeAnswerHeaderSend()
local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then hc.monitor_text_color = monitor_color end end
table.insert(monitor_string_array[hc.monitor_index], {priority=40, text='(Test priority 2)'}) table.insert(monitor_string_array[hc.monitor_index], {priority=17, text='(Test priority 1)'}) table.insert(monitor_string_array[hc.monitor_index], {priority=55, text='(Test priority 4)'}) table.insert(monitor_string_array[hc.monitor_index], {priority=53, text='(Test priority 3)'})
table.sort(monitor_string_array[hc.monitor_index], function(record1, record2) return record1.priority <= record2.priority end ) local delimiter = ' - ||| - ' for i,record in ipairs(monitor_string_array[hc.monitor_index]) do monitor_string_array[hc.monitor_index][i] = record.text end monitor_show(table.concat(monitor_string_array[hc.monitor_index], delimiter)) end
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 01 августа 2017, 21:22:44
Thank you very much.
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 04 августа 2017, 16:03:03
How i can add color to monitor? Monitor not accepted value color? ... function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} monitor_string_array[hc.monitor_index] = {}
monitor_color_array = monitor_color_array or {} monitor_color_array = {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array[hc.monitor_index], {priority=10, text='Load from Cache'}) table.insert(monitor_color_array, {priority=10, color='102, 150, 0'}) else hc.action = 'save' table.insert(monitor_string_array[hc.monitor_index], {priority=11, text='Saved to Cache'}) end
testa = monitor_color_array[#monitor_color_array].color -- for testing 1 hc.put_msg(1, 'Test OK: '..testa) -- for testing 2
end
function BeforeAnswerHeaderSend()
local function rgb(r, g, b) local r = r local g = g*256 local b = b*256*256 return r+g+b end
local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then rgb(monitor_color) hc.monitor_text_color = monitor_color end end
table.insert(monitor_string_array[hc.monitor_index], {priority=5, text='('..type_define..')'}) table.insert(monitor_string_array[hc.monitor_index], {priority=40, text='(Test priority 2)'})
table.sort(monitor_string_array[hc.monitor_index], function(record1, record2) return record1.priority <= record2.priority end )
table.sort(monitor_color_array, function(record1, record2) return record1.priority <= record2.priority end )
local delimiter = ' - ||| - ' for i,record in ipairs(monitor_string_array[hc.monitor_index]) do monitor_string_array[hc.monitor_index][i] = record.text end for i,record in ipairs(monitor_color_array) do monitor_color_array[i] = record.color end
monitor_show(table.concat(monitor_string_array[hc.monitor_index], delimiter), monitor_color_array[1].color) end table.insert(monitor_color_array, {priority=10, color=102, 150, 0}) not accepted too
Название: Re: Monitor or script looping problem
Отправлено: Михаил от 04 августа 2017, 16:19:03
monitor_show(table.concat(monitor_string_array[hc.monitor_index], delimiter), rgb(255,0,0))
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 04 августа 2017, 23:23:22
Yes, but i priority apply on both... monitor string, and monitor color... if is header not exist, etc.. then select priority color and color from define other priority is ignored. I dont know how get first line (or first priority) color from table color after sort and ipairs. I study function pairs and ipairs vs. table formats - basic ok, but this is advanced.
Do you know quality sources for study LUA? On Google is first search basic and advanced i dont find.
Название: Re: Monitor or script looping problem
Отправлено: Михаил от 04 августа 2017, 23:53:13
function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} monitor_string_array[hc.monitor_index] = {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array[hc.monitor_index], { priority=10, text='Load from Cache', color={102,150,0} }) else hc.action = 'save' table.insert(monitor_string_array[hc.monitor_index], { priority=11, text='Saved to Cache' }) end end
function BeforeAnswerHeaderSend()
local function rgb(r, g, b) return r + g*256 + b*256*256 end
local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then hc.monitor_text_color = rgb(table.unpack(monitor_color)) end end
table.insert(monitor_string_array[hc.monitor_index], { priority=40, text='(Test priority 2)' }) table.insert(monitor_string_array[hc.monitor_index], { priority=17, text='(Test priority 1)' }) table.insert(monitor_string_array[hc.monitor_index], { priority=55, text='(Test priority 4)' }) table.insert(monitor_string_array[hc.monitor_index], { priority=53, text='(Test priority 3)' })
table.sort(monitor_string_array[hc.monitor_index], function(record1, record2) return record1.priority <= record2.priority end ) local texts = {} for i,record in ipairs(monitor_string_array[hc.monitor_index]) do texts[i] = record.text end local delimiter = ' - ||| - ' monitor_show(table.concat(texts, delimiter), monitor_string_array[hc.monitor_index][1].color) end
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 05 августа 2017, 00:00:04
Do you know quality sources for study LUA? On Google is very global - as first search basic and advanced i dont find.
Название: Re: Monitor or script looping problem
Отправлено: Михаил от 05 августа 2017, 00:06:19
I study this (http://www.lua.org/manual/5.2/)
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 05 августа 2017, 00:13:17
No i have as: ... function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} monitor_string_array[hc.monitor_index] = {}
monitor_color_array = monitor_color_array or {} monitor_color_array = {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array[hc.monitor_index], {priority=10, text='Load from Cache'}) table.insert(monitor_color_array, {priority=20, color='102, 150, 0'}) else hc.action = 'save' table.insert(monitor_string_array[hc.monitor_index], {priority=11, text='Saved to Cache'}) end
testa = monitor_color_array[#monitor_color_array].color -- for testing 1 hc.put_msg(1, 'Test OK: '..testa) -- for testing 2
end
function BeforeAnswerHeaderSend()
local function rgb(r, g, b) local r = r local g = g*256 local b = b*256*256 return r+g+b end
local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then rgb(monitor_color) hc.monitor_text_color = monitor_color end end
table.insert(monitor_string_array[hc.monitor_index], {priority=5, text='('..type_define..')'}) table.insert(monitor_string_array[hc.monitor_index], {priority=40, text='(Test priority 2)'})
if re.match(hc.answer_header, [[^HTTP/1\.1\s403[^\r\n]+]]) and not re.match(hc.answer_header, [[^Server: HandyCache[^\r\n]+]]) then table.insert(monitor_color_array, {priority=1, color='153, 0, 0'}) end
table.sort(monitor_string_array[hc.monitor_index], function(record1, record2) return record1.priority <= record2.priority end )
table.sort(monitor_color_array, function(record1, record2) return record1.priority <= record2.priority end )
local delimiter = ' - ||| - ' for i,record in ipairs(monitor_string_array[hc.monitor_index]) do monitor_string_array[hc.monitor_index][i] = record.text end for i,record in ipairs(monitor_color_array) do monitor_color_array[i] = record.color end
monitor_show(table.concat(monitor_string_array[hc.monitor_index], delimiter), monitor_color_array[1].color) end
Название: Re: Monitor or script looping problem
Отправлено: Михаил от 05 августа 2017, 02:41:13
local function set_color(color, priority) local data = MY_EXTENSION_DATA[hc.monitor_index]
local function rgb(r, g, b) return r + g*256 + b*256*256 end
if not data.color_priority or priority < data.color_priority then data.color = rgb(table.unpack(color)) data.color_priority = priority end end
function RequestHeaderReceived() MY_EXTENSION_DATA = MY_EXTENSION_DATA or {} MY_EXTENSION_DATA[hc.monitor_index] = { monitor_string_array={} } local data = MY_EXTENSION_DATA[hc.monitor_index] if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(data.monitor_string_array, {priority=10, text='Load from Cache'}) set_color({102,150,0}, 20) else hc.action = 'save' table.insert(data.monitor_string_array, {priority=11, text='Saved to Cache'}) end
-- testa = monitor_color_array[#monitor_color_array].color -- for testing 1 -- hc.put_msg(1, 'Test OK: '..testa) -- for testing 2
end
function BeforeAnswerHeaderSend() local data = MY_EXTENSION_DATA[hc.monitor_index]
local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then hc.monitor_text_color = monitor_color end end
table.insert(data.monitor_string_array, {priority=5, text='(..type_define..)'}) table.insert(data.monitor_string_array, {priority=40, text='(Test priority 2)'})
if re.match(hc.answer_header, [[\A\S++\s++403\s(?!.*?^Server:\s*+HandyCache)]]) then set_color({153,0,0}, 1) end
table.sort(data.monitor_string_array, function(record1, record2) return record1.priority <= record2.priority end )
local texts = {} for i,record in ipairs(data.monitor_string_array) do texts[i] = record.text end
local delimiter = ' - ||| - ' monitor_show(table.concat(texts, delimiter), data.color) end
Sorry but I can't write all code for you. I show a few methods that you can use further by own efforts.
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 05 августа 2017, 20:56:06
Yes. Thank you for redirect for recomended sources and help with script. I understand a little more about this programming thank you.
Randomly show S.0 lines. I can eliminate on HC or Extension layer?
Название: Re: Monitor or script looping problem
Отправлено: Михаил от 05 августа 2017, 21:24:11
"S.0" must appears only when you use "Load to cache" command (for example, from HC monitor context menu). It must not appears randomly.
Название: Re: Monitor or script looping problem
Отправлено: truefriend-cz от 05 августа 2017, 21:58:13
Sorry, randomly on background, but one time yes, and many times no... if same situation state.
URL where S.0 is http://handycache.ru/downloads/curver.txt
Solution: Eliminated if uncheck update in Options -> View -| Check for new version availability every ... days.
|