I have a problem with the folder "pong-1" that contains "main.lua" and "push.lua". When I select them into "LÖVE", it says:
>Error
push.lua:71: bad argument #1 to 'insert' (table expected, got number)
[C]: in function 'insert'
push.lua:71: in function 'setupCanvas'
main.lua:12: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
I tried with the outdated version of push.lua (which offers the source code of the course) as well as the newest version I could find, but neither of them worked. Both display the same error message. What could be the problem?
function push:setupCanvas(canvases)
table.insert(canvases, { name = "_render", private = true }) --final render
self._canvas = true
self.canvases = {}
for i = 1, #canvases do
push:addCanvas(canvases[i])
end
return self
end
This functions expects canvases to be a table value.
You provide a number value VIRTUAL_WIDTH in your function call
push:setupCanvas(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH,
WINDOW_HEIGHT,{ fullscreen = false, resizable = false, vsync = true })
instead.
Looks like you're confusing setupCanvas with setupScreen
Related
here are the errors, this problem only occurs when opening Python files
i am using coc.nvim to complete the code
idk what course this problem
any ideas will be appreciated
Error detected while processing BufNewFile Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:22: Error executing lua: /usr/share/nvim/runtime/filetype.lua:23: Vim(for):E715: Dictionary required
stack traceback:
[C]: in function 'nvim_cmd'
/usr/share/nvim/runtime/filetype.lua:23: in function </usr/share/nvim/runtime/filetype.lua:22>
[C]: in function 'nvim_buf_call'
/usr/share/nvim/runtime/filetype.lua:22: in function </usr/share/nvim/runtime/filetype.lua:11>
stack traceback:
[C]: in function 'nvim_buf_call'
/usr/share/nvim/runtime/filetype.lua:22: in function </usr/share/nvim/runtime/filetype.lua:11>
You should declare the ale_linters. I faced the same error for Python and hence I realized my old configuration was like vim.g.ale_linters = {}
50 vim.g.ale_linters = {
1 ['*'] = {'ale_linters'},
2 ['python'] = {'flake8'},
3 ['sh'] = {'shellcheck'},
4 ['zsh'] = {'shellcheck'},
5 ['vim'] = {'vint'},
6 ['lua'] = {'luacheck'},
7 ['go'] = {'golangci-lint'},
8 ['dockerfile'] = {'dockerfile_lint'},
9 }
I'm trying to create and indexed array of functions to call him with changed params, like this:
local function wubba(lubba)
return lubba
end
local dub = {
["wubba"] = {func = wubba(lubba)}
}
print(dub["wubba"].func("hi"))
But in all my tries i got errors, i can't figure out how to do it. Anyone can help me?
lua: wubba.lua:9: attempt to call field 'func' (a nil value)
stack traceback:
wubba.lua:9: in main chunk
[C]: in ?
Solved, just not to store with params:
local dub = {
["wubba"] = {func = wubba}
}
I would like to know if there's a way for the 'load' function to get a variable value from a local variable instead of a global variable ?
Say that I've got a string like this 'trade.version == 2' that I want to execute with the 'load' function inside a function taking the trade as parameter.
function doTest( trade, test )
-- inside the string 'test', I would like that any reference to 'trade'
-- refer to the function parameter instead of a global variable
if ( assert(load("return "..test))() ) then
-- do something
end
end
a_userdata = { version = 2 }
-- Calling the function above
doTest( a_userdata , "trade.version == 2" )
[string "return trade.version == 2"]:1: attempt to index global 'trade' (a nil value)
stack traceback:
[string "return trade.version == 2"]:1: in main chunk
stdin:2: in function 'doTest'
stdin:1: in main chunk
[C]: in ?
As a workaround, I have defined a global variable and it's working pretty fine.
But I would like to avoid this global variable.
Thank you very much
function doTest( trade, test )
-- inside the string 'test', I would like that any reference to 'trade'
-- refer to the function parameter instead of a global variable
if assert(load("local trade = ...; return "..test))(trade) then
-- do something
print('Yes, version equals to 2')
end
end
a_userdata = { version = 2 }
-- Calling the function above
doTest( a_userdata , "trade.version == 2" )
I have problems in understanding how a class variable in Torch works.
I did the following:
mydata=torch.class('something')
I checked the User variable by typing who() and it shows:
== User Variables ==
[_RESULT] = table - size: 0
[mydata] = table - size: 0
[something] = table - size: 0
I first of all tried to delete mydata by
mydata=nil
it works. mydata is now freed and can be reinitialized to any values. But when I tried to delete the variable something by typing
soemthing=nil
It seems it's not working even though the variable something was not list in who() anymore. When I try:
mydata2=torch.class('something')
the error pops out:
/data/torch/install/share/lua/5.1/torch/init.lua:65: something has been already assigned a factory
stack traceback:
[C]: in function 'newmetatable'
/data/torch/install/share/lua/5.1/torch/init.lua:65: in function 'class'
[string "mydata2=torch.class('something')"]:1: in main chunk
[C]: in function 'xpcall'
/data/torch/install/share/lua/5.1/trepl/init.lua:648: in function 'repl'
/data/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk
[C]: at 0x00406670
Could anyone tell me the reason behind it?
torch.class() stores the class metatable in the lua-registry, see http://www.lua.org/pil/27.3.1.html and the luaT_lua_newmetatable() function in the torch C-backend.
In order to unregister an existing class it is necessary to remove the entry from the lua-registry. You can access the registry from lua with help of the debug.getregistry() function.
With removeal from registry your example works:
mydata = torch.class('something')
mydata = nil
soemthing = nil
-- remove the global registration:
debug.getregistry()['something'] = nil
-- now it is possible to register the class again
mydata2 = torch.class('something')
I am trying to create an operator '!' that returns the print function.
I am getting the following error:
line 15: attempt to call a number value
stack traceback:
t.lua:15: in main chunk
[C]: ?
My code is below:
local opTable = {}
debug.setmetatable(0,{
_call = function(a,op)
return opTable[op](a)
end
})
local function addOp(operator,f)
opTable[operator] = f
end
addOp('!',print)
print((5)'!')
It seems this should work, because techniqe #3 on http://lua-users.org/wiki/CustomOperators uses almost exactly the same method.