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
Hi,
As what the docs say username for on_message_publish function should be string, but when I debug it using print and some helper functions I realize that its a table without any data in it.
This is a function I used to print username and it gives me an empty table.
functionprint_table(node)
localcache, stack, output= {},{},{}
localdepth=1localoutput_str="{\n"whiletruedolocalsize=0fork,vinpairs(node) dosize=size+1endlocalcur_index=1fork,vinpairs(node) doif (cache[node] ==nil) or (cur_index>=cache[node]) thenif (string.find(output_str,"}",output_str:len())) thenoutput_str=output_str..",\n"elseifnot (string.find(output_str,"\n",output_str:len())) thenoutput_str=output_str.."\n"end-- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge stringstable.insert(output,output_str)
output_str=""localkeyif (type(k) =="number" ortype(k) =="boolean") thenkey="["..tostring(k).."]"elsekey="['"..tostring(k).."']"endif (type(v) =="number" ortype(v) =="boolean") thenoutput_str=output_str..string.rep('\t',depth) ..key.." = "..tostring(v)
elseif (type(v) =="table") thenoutput_str=output_str..string.rep('\t',depth) ..key.." = {\n"table.insert(stack,node)
table.insert(stack,v)
cache[node] =cur_index+1breakelseoutput_str=output_str..string.rep('\t',depth) ..key.." = '"..tostring(v).."'"endif (cur_index==size) thenoutput_str=output_str.."\n" ..string.rep('\t',depth-1) .."}"elseoutput_str=output_str..","endelse-- close the tableif (cur_index==size) thenoutput_str=output_str.."\n" ..string.rep('\t',depth-1) .."}"endendcur_index=cur_index+1endif (size==0) thenoutput_str=output_str.."\n" ..string.rep('\t',depth-1) .."}"endif (#stack>0) thennode=stack[#stack]
stack[#stack] =nildepth=cache[node] ==nilanddepth+1ordepth-1elsebreakendend-- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge stringstable.insert(output,output_str)
output_str=table.concat(output)
print(output_str)
end
And this is my on_message_publish :
functionon_message_publish(clientid, username, topic, payload, qos, retain)
print_table(username)
-- do your job herereturntopic, payload, qos, retainend
The text was updated successfully, but these errors were encountered:
I also facing same issue in string handling. I need to remove some character from my string then return to the topic but it seems that gmatch function or for loop statement do not work on lua_hook plugins.
function on_message_publish(clientid, username, topic, payload, qos, retain)
dataStr = payload:match("(%[.-%])")
string = ''
for data in dataStr:gmatch("%b{}") do
string = string .. data:match(':"(.-)",') .. ';' .. data:match('e":(.-)}') .. ','
end
return topic, string, qos, retain
end
Hi,
As what the docs say username for
on_message_publish
function should be string, but when I debug it using print and some helper functions I realize that its a table without any data in it.This is a function I used to print username and it gives me an empty table.
And this is my
on_message_publish
:The text was updated successfully, but these errors were encountered: