SendChatMessage is a protected function in 1.13.3? - lua

I'm maintaining an addon that has a feature that uses SendChatMessage. But if I call it, I get the error:
Date: 2020-01-01 12:23:01
ID: 1
Error occured in: AddOn: LunarSphere
Count: 1
Message: Warning: AddOn LunarSphere attempted to call a protected function (UNKNOWN()) which may require interaction.
Debug:
[C]: ?
[C]: SendChatMessage()
LunarSphere\lib\moduleSpeech.lua:1087: RunScript()
LunarSphere\lib\moduleSpeech.lua:403: CheckCurrentAction()
LunarSphere\lib\moduleSpeech.lua:202:
LunarSphere\lib\moduleSpeech.lua:179
Locals:
None
The code in question is:
SendChatMessage("msg" ,"SAY");
Really, that's it.
I can use /script SendChatMessage("msg" ,"SAY"); in the client though.
Is there a possible workaround? At least for the SAY channel?
Thanks!

Yes, it's a hardware event protected function now, see https://wow.gamepedia.com/API_SendChatMessage
If you run the script from the chat window it would work, but not anymore in an addon

Related

NeoVim - Check if a Vim function exists from Lua

I plan on using vim-plug with NeoVim. So, my init.lua file will have function calls such as
vim.fn['plug#begin'](vim.fn.stdpath('data') .. '/plugged')
vim.fn['plug#']('hoob3rt/lualine.nvim')
However, I don't want to assume vim-plug is definitely installed. I want my init.lua file to degrade gracefully if vim-plug is not installed, rather than throwing an error
E5113: Error while calling lua chunk: Vim:E117: Unknown function: plug#begin
stack traceback:
[C]: in function 'plug#begin'
/Users/andy/.config/nvim/init.lua:8: in main chunk
How can I check if the vim-plug functions exist before attempting to call them?
I tried print(vim.fn['plug#begin']) but that for some reason prints a non-null value: function: 0x0104ba36f0, even though the function doesn't exist.
I tried print(vim.fn['plug#begin']) but that for some reason prints a non-null value: function: 0x0104ba36f0, even though the function doesn't exist.
Presumably it's returning a function that throws the error you are getting. I would thus recommend using pcall:
local success, error = pcall(vim.fn['plug#begin'], vim.fn.stdpath('data') .. '/plugged')
if not success then --[[fail gracefully]] end
caveat: this will catch any error, so you'll probably want to perform some check like if error:find"Unknown function" then ... end to only catch this specific error.

Error running call reference function for resource es_extended fiveM

Basically have another fivem es_extended issue where I am getting unwelcome errors everytime users try and join my server and show their money as undefined, and also not allow them to save their clothing.
I've dropped tables from my database and re-added them to no avail.
stack traceback:
#es_extended/server/main.lua:155: in upvalue 'ref'
citizen:/scripting/lua/scheduler.lua:391: in function <citizen:/scripting/lua/scheduler.lua:390>
[C]: in function 'xpcall'
citizen:/scripting/lua/scheduler.lua:390: in function <citizen:/scripting/lua/scheduler.lua:389>
stack traceback:
[C]: in function 'error'
citizen:/scripting/lua/scheduler.lua:405: in function <citizen:/scripting/lua/scheduler.lua:374>
Error: Unhandled error in timer: Error: BUFFER_SHORTAGE
Error: BUFFER_SHORTAGE
at n.e [as reserve] (citizen:/scripting/v8/msgpack.js:29:12766)
at h (citizen:/scripting/v8/msgpack.js:29:15761)
at n.r [as decode] (citizen:/scripting/v8/msgpack.js:29:13908)
at n.fetch (citizen:/scripting/v8/msgpack.js:29:6972)
at n.u [as read] (citizen:/scripting/v8/msgpack.js:29:12076)
at Object.n [as decode] (citizen:/scripting/v8/msgpack.js:29:7097)
at unpack (citizen:/scripting/v8/main.js:20:33)
at citizen:/scripting/v8/main.js:51:20
at setImmediate (mysql-async.js:4962:9)
at Object.callback (citizen:/scripting/v8/timer.js:96:21)
Expected should be no errors at all, and thats the error messages that come along when a new person joins the server for the first time.
All ESX 1.* are officially discontinued due to bugs in latest versions, based on ESX recommendations you can try Extended Mode, works fine with minimum amount of bugs

Torch 7/Lua cannot require a .so file, but package.loadlib() can

I get a problem when playing Torch 7 code. I have a shared library libhashnn.so file, and I want to load the functions in Torch 7 script, so I use this expression: require 'libhashnn', but the trepl gives an error.
However, if I use package.loadlibfunction, it does work. Here are the results, but I don't know why I can't use require, how can I use require to load lib successfully?
require'libhashnn'
/home/dazhen/torch/install/share/lua/5.1/trepl/init.lua:383: bad argument #1 to '?' (table expected, got string)
stack traceback:
[C]: in function 'error'
/home/dazhen/torch/install/share/lua/5.1/trepl/init.lua:383: in function 'require'
[string "_RESULT={require'libhashnn'}"]:1: in main chunk
[C]: in function 'xpcall'
/home/dazhen/torch/install/share/lua/5.1/trepl/init.lua:650: in function 'repl'
...zhen/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
and
f=package.loadlib('libhashnn.so' ,'luaopen_libhashnn')
[0.0195s]
th> f
function: 0x41630f38
Try calling the function that package.loadlib gives you. I bet you will then get the same error that you get when you use require.
To understand why: require does the equivalent of package.loadlib and then calls that function so that the module that you are loading can initialize itself. With just package.loadlib, this initialization is not done and so the error that occurs during initialization does not show up.
I don't know what hashnn is and so I cannot tell you why it is broken, but looking at /home/dazhen/torch/install/share/lua/5.1/trepl/init.lua line 383 might be a good start to figure out what is going on.

Issue with neuralnetwork_turial.lua with data preprocessing

I have installed the torch deep learning module by first git clone-ing and later using luarocks make and the installation was succussful. The require 'dp' works well in the torch prompt.
But when I try to execute the neuralnetwork_tutorial.lua(th neuralnetwork_tutorial.lua), it throws the following errors.
Tanny #neuralnetwork_tutorial.lua: About to initiate: datasource = dp.Mnist{input_preprocess = dp.Standardize()}
Tanny #/home/ubuntu/binaries/torches/torch/install/share/lua/5.1/dp/preprocess/standardize.lua: Marked presence!!!
Tanny #/home/ubuntu/binaries/torches/torch/install/share/lua/5.1/dp/torch/File.lua says: #177 typeidx= 3
Tanny #/home/ubuntu/binaries/torches/torch/install/share/lua/5.1/dp/torch/File.lua says: #177 typeidx= 1
Tanny #/home/ubuntu/binaries/torches/torch/install/share/lua/5.1/dp/torch/File.lua says: #177 typeidx= 4
Tanny #/home/ubuntu/binaries/torches/torch/install/share/lua/5.1/dp/torch/File.lua says: #177 typeidx= 0
Tanny #/home/ubuntu/binaries/torches/torch/install/share/lua/5.1/dp/torch/File.lua says: #177 typeidx= 28
Tanny #/home/ubuntu/binaries/torches/torch/install/share/lua/5.1/dp/torch/File.lua says: #259 typeidx= 28
/home/ubuntu/binaries/torches/torch/install/bin/luajit: ...aries/torches/torch/install/share/lua/5.1/torch/File.lua:260: unknown object
stack traceback:
[C]: in function 'error'
...aries/torches/torch/install/share/lua/5.1/torch/File.lua:260: in function 'readObject'
...aries/torches/torch/install/share/lua/5.1/torch/File.lua:252: in function 'readObject'
...aries/torches/torch/install/share/lua/5.1/torch/File.lua:277: in function 'loadData'
...es/torches/torch/install/share/lua/5.1/dp/data/mnist.lua:74: in function 'loadTrainValid'
...es/torches/torch/install/share/lua/5.1/dp/data/mnist.lua:61: in function '__init'
...aries/torches/torch/install/share/lua/5.1/torch/init.lua:50: in function <...aries/torches/torch/install/share/lua/5.1/torch/init.lua:46>
[C]: in function 'Mnist'
neuralnetwork_tutorial.lua:16: in main chunk
[C]: in function 'dofile'
...ches/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:131: in main chunk
[C]: at 0x0804d650
I put some print statements in those scripts to understand the flow. I happen to notice that in File.lua the first step after getting the object is to determine the type of the object; of which 8 have been declared. The types have been declared through 0 to 7, 0 being TYPE_NIL. However the code fails, as it detects a type 28(??).
Kindly any help where I am going wrong? Or where to look into to find the issue?
P.S.: The script downloads the data on its own, however due to certain standard corporate proxy setting issues, it could not download. Therefore, I personally downloaded the data MNIST and stored it in the specific data directory. If this could be a clue??
Okay, so it was a bug in the code (serialized MNIST wasn't cross-platform). Fixed by serializing dataset using ascii format instead of binary.

Lua: How to call error without stack trace

I'm using Lua to parse scripts written in some language (let's call it L) and create Lua-code that can be run by e.g. LuaJIT. But to simplify debugging for the users, I want to map the run time errors given by Lua/LuaJIT to the correct line in the L-files. I do this by xpcalling the created Lua-code, translating the error message and stacktrace and then calling error with this message. Unfortunately this gives me two stack traces, one created by me and one tracing back to the function that called error. Is it possible to get rid of this stack trace, or is there some better way of doing this?
local status, err = xpcall(loadedCode, debug.traceback)
if not status then
error(createANewErrorMessageWithPrettyTraceback(err),0)
end
Output:
luajit: ./my/file.name:5: Some error message
stack traceback:
my pretty traceback
stack traceback:
[C]: in function 'error'
./my/file/calling/error.lua:44: in function <./my/file/calling/error.lua:26>
./my-main:16: in main chunk
[C]: at 0x00404180
I know that e.g. Moonscript does something similar to this, but as far as I can see they just write the new error message to stderr and then continues as normal, instead of stopping the program which is what I want to do.
There is a possibility of doing this and then calling error with no arguments, which will make the program fail (actually I think it's error that fails), but this feels like quite an ugly solution, so I'll rather keep the stupid second trace than doing that.
PS: I assume what the title asks actually doesn't work (as error only takes two arguments), so what I'm actually asking is more how something like this can be achieved. (Are there other functions that do similar things perhaps, or where I should look to figure out how to write that function myself.)
Edit: Is it perhaps possible to edit the function that error's using to get its traceback, as it is with debug.traceback?
I wanted to do something similar (only from Lua directly) and I ended up overwriting debug.traceback function itself to change the stack trace to suit my needs. My code is below; see if this method works for you as well:
local dtraceback = debug.traceback
debug.traceback = function (...)
if select('#', ...) >= 1 then
local err, lvl = ...
if err and type(err) ~= 'thread' then
local trace = dtraceback(err, (lvl or 2)+1)
if genv.print == iobase.print then -- no remote redirect
return trace
else
genv.print(trace) -- report the error remotely
return -- don't report locally to avoid double reporting
end
end
end
-- direct call to debug.traceback: return the original.
-- debug.traceback(nil, level) doesn't work in Lua 5.1
-- (http://lua-users.org/lists/lua-l/2011-06/msg00574.html), so
-- simply remove first frame from the stack trace
return (dtraceback(...):gsub("(stack traceback:\n)[^\n]*\n", "%1"))
end
You could simply display the modified traceback that you want and exit.
local function errh(err)
print(createANewErrorMessageWithPrettyTraceback(debug.traceback(err, 2)))
os.exit(-1) -- error code
end
local status, result = xpcall(loadedCode, errh)
-- The script will never reach this point if there is an error.
print(result)

Resources