dofile works but call a stack traceback - lua

main.lua
dofile("example.lua")
example.lua
print "Hello World"
results in:
Hello World
lua: main.lua:1: attempt to call a nil value
stack traceback:
main.lua:1: in main chunk
[C]: in ?
But I don't understand why?

Related

ray-x/go.nvim attempt to index a boolean value

I'm trying to add ray-x/go.nvim plugin to my neovim setup.
I added the plugin in my plugins.lua
Then I'm trying to setup the plugin using require('go').setup().
Error detected while processing /home/rajkumar/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/rajkumar/.config/nvim/lua/lsp/language_servers.lua:176: attempt to index a boolean value
stack traceback:
/home/rajkumar/.config/nvim/lua/lsp/language_servers.lua:176: in main chunk
[C]: in function 'require'
/home/rajkumar/.config/nvim/lua/lsp/init.lua:3: in main chunk
[C]: in function 'require'
/home/rajkumar/.config/nvim/init.lua:12: in main chunk
How can I fix this issue?

How to add a Lua library on VS

So I am a beginner in programming and I decided to learn Lua. I am adding a library to Lua (push: require 'push') but I am getting this error when I am running it on LOVE2D. What should I do?
Error
main.lua:1: module 'push' not found:
no field package.preload['push']
no 'push' in LOVE game directories.
no file 'push' in LOVE paths.
no file './push.lua'
no file '/usr/local/share/luajit-2.1.0-beta3/push.lua'
no file '/usr/local/share/lua/5.1/push.lua'
no file '/usr/local/share/lua/5.1/push/init.lua'
no file './push.so'
no file '/usr/local/lib/lua/5.1/push.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
Traceback
[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'require'
main.lua:1: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

'end' expected near '<eof>' for map import for lua file

Error
Syntax error: main.lua:8: 'end' expected (to close 'function' at line 5) near '<eof>'
Traceback
[love "callbacks.lua"]:228: in function 'handler'
[C]: at 0x010558a810
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
I am getting the above error when I am trying to import a game map for my love2D game.
My code is below:
function love.load()
sti = require'lib/sti'
gameMap = sti('Maps/test_map.lua')
end
function love.draw()
gameMap:draw()
end
sti is a library which I am using to get the map into love. I learnt this from a youtube tutorial.
try looking at the function gameMap:draw, you might have forgotten an end on it

Loadstring Error: attempted to call a nil value

loadstring("
\45\45\32\80\117\116\32\115\99\114\105\112\116\32\104\101\114\101\10\112\114\105\110\116\40\34\104\105\34\41\10")()
I keep getting an error stating this:
lua: /tmp/044957038/main.lua:12: attempt to call a nil value (global 'loadstring')
stack traceback:
/tmp/044957038/main.lua:12: in main chunk
[C]: in ?
Can anyone help me? (I’m using glot.io to run my script.)
Based on the comments and some testing in glot, this should work (the print() is just for reference):
print("\45\45\32\80\117\116\32\115\99\114\105\112\116\32\104\101\114\101\10\112\114\105\110\116\40\34\104\105\34\41\10")
load("\45\45\32\80\117\116\32\115\99\114\105\112\116\32\104\101\114\101\10\112\114\105\110\116\40\34\104\105\34\41\10")()
Output
-- Put script here
print("hi")
hi

lua traceback without message but with level

Here is something fun:
-- file1.lua
require('./file2')
-- file2.lua
print("default:")
print(debug.traceback())
print("\n")
print("with both options:")
print(debug.traceback("prefix", 2))
print("\n")
print("nil message:")
print(debug.traceback(nil, 2))
This is what I get
default:
stack traceback:
./file2.lua:3: in main chunk
[C]: in function 'require'
file1.lua:2: in main chunk
[C]: ?
with both options:
prefix
stack traceback:
[C]: in function 'require'
file1.lua:2: in main chunk
[C]: ?
nil message:
nil
So if I want to have a level, I MUST also include a message? How do I get this to work without providing a message?

Resources