Keep Lua tmpfile after execute - lua

Uploades file represented as tmpfile() and will be removed then script exits.
How to hardlink this file to keep its content after removing tmpfile?
How to get name of file by its handle?
> a=io.tmpfile()
> print(a)
file (0x20c8790)
> lfs=require"lfs"
> lfs.link(a,"/tmp/aaaa")
stdin:1: bad argument #1 to 'link' (string expected, got FILE*)
stack traceback:
[C]: in function 'lfs.link'
stdin:1: in main chunk
[C]: in ?
This file is too big to copy it by byte to another.

io.tmpfile uses tmpfile of stdio.h, so it wont be possible to adjust this exported function.
you can use libraries such as pl.path to get full path of temp file.

Related

Requiring luasnip to neovim causes errors

I am trying to use luasnip.
The configuration I am using is AstroNvim.
The modifications I made to this configuration are :
require("luasnip.loaders.from_snipmate").lazy_load() at the end of init.lua
Made a directory snippets in the same directory of init.lua, and added some basic snipmate styled snippets inside.
Commands Like :LuaSnipListAvailable works well, and snippets from friendly-snippets works well too.
However the following error message pops up when opening neovim.
Error detected while processing /Users/myusername/.config/nvim/init.lua:
E5113: Error while calling lua chunk: ...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:171: Vim(echomsg):E121: Undefined variable: Error
stack traceback:
[C]: in function 'cmd'
...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:171: in function <...m/site/pack/packer/start/packer.nvim/lua/packer/load.lua:16
7>
/Users/myusername/.local/share/nvim/packer_compiled.lua:496: in function </Users/myusername/.local/share/nvim/packer_compiled.lua:485>
[C]: in function 'require'
/Users/myusername/.config/nvim/init.lua:23: in main chunk
I tried other methods of adding snippets, but any sort of require("luasnip") seems to break all.

using a batch file to open lua love is giving error

I just started learning love and I've tried opening love with a batch file, while it does open it gives this error
Error
[love "boot.lua"]:321: No code to run
Your game might be packaged incorrectly.
Make sure main.lua is at the top level of the zip.
Traceback
[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'error'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
however when dragging the whole folder inside of love it works perfectly, does somebody know how can I fix this?
Error message
Error message indicates, that you did not set correct path to your code, so the is no code to run. It should be folder containing main.lua
Simple batch file
Place the following code to file start.bat:
#ECHO OFF
"C:\Program Files\LOVE\love.exe" "C:\path\to\game\folder"
(replace C:\path\to\game\folder with actual path to folder containing main.lua and if you have love.exe elsewhere, also replace it to the correct path)
And then, you can run your code by double-clicking the start.bat file
Some helpful links:
How to run your game
Batch file example

neovim init.lua module "lua.plguins" not found

I'm in the configuration neovim
I added the configuration file in C:\Users\wupan\AppData\Local\nvim\init.lua
require("lua.plugins")
and C:\Users\wupan\AppData\Local\nvim\lua\plugins.lua
return require('packer').startup(function()
use "wbthomason/packer.nvim"
end)
After the start-up neovim
Error detected while processing C:\Users\wupan\AppData\Local\nvim\init.lua:
E5113: Error while calling lua chunk: C:\Users\wupan\AppData\Local\nvim\init.lua:1: module 'lua.plugins' not found:
no field package.preload['lua.plugins']
no file '.\lua\plugins.lua'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\lua\plugins.lua'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\lua\plugins\init.lua'
no file '.\lua\plugins.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\plugins.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\loadall.dll'
no file '.\lua.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua.dll'
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\loadall.dll'
stack traceback:
[C]: in function 'require'
C:\Users\wupan\AppData\Local\nvim\init.lua:1: in main chunk
Press ENTER or type command to continue
May I ask why
I tried to install Lua test the require
scoop install lua
C:\Users\wupan\code\lua\test.lua
require("hello")
C:\Users\wupan\code\lua\hello.lua
print("hello world")
There are also problems
C:\Users\wupan\scoop\apps\lua\current\lua54.exe: .\test.lua:1: module 'hello' not found:
no field package.preload['hello']
no file 'C:\Users\wupan\scoop\apps\lua\current'
no file 'C:\Users\wupan\scoop\apps\lua\current'
stack traceback:
[C]: in function 'require'
.\test.lua:1: in main chunk
[C]: in ?
Problem analysis
Let's use the following example which you gave us:
C:\Users\wupan\AppData\Local\nvim\init.lua
require("lua.plugins")
C:\Users\wupan\AppData\Local\nvim\lua\plugins.lua
return require('packer').startup(function()
use "wbthomason/packer.nvim"
end)
And now let's take a look into your error message:
no file 'C:\Users\wupan\scoop\apps\neovim\current\bin\lua\lua\plugins.lua'
The important part is the bin\lua\lua thing here. It's because your
require("lua.plugins") starts to look up a directory in one of your runtime
path (see :h rtp for more information).
Solution
You just need to fix your content in
C:\Users\wupan\AppData\Local\nvim\init.lua to:
require("plugins")
because then neovim will look up a directory which is named plugins in
C:\Users\wupan\scoop\apps\neovim\current\bin\lua for example, since its in
your runtime path.
Little note
You can change your content from
C:\Users\wupan\AppData\Local\nvim\lua\plugins.lua to:
require('packer').startup(function()
use "wbthomason/packer.nvim"
end)
or how I did it:
local packer = require('packer')
packer.startup(function(use)
use 'wbthomason/packer.nvim'
end)
That makes it a little bit more readable in my opinion :)

Torch, testing issue - imagenet-multiGPU.torch

I am a newbies to torch. I have trainined my model according to 2 classes via this instruction https://github.com/soumith/imagenet-multiGPU.torch (number of classes is modifed) then, I wantted to test my model. These lines of codes are writen in instruction for testing:
dofile('donkey.lua')
img = testHook({loadSize}, 'test.jpg')
model = torch.load('model_10.t7')
if img:dim() == 3 then
img = img:view(1, img:size(1), img:size(2), img:size(3))
end
predictions = model:forward(img:cuda())
I got errors at the initial line of codes while I was trying to write.
When I try to write ;
th> dofile('donkey.lua')
I get these errors;
th> dofile("donkey.lua")
donkey.lua:18: attempt to index global 'opt' (a nil value)
stack traceback:
donkey.lua:18: in main chunk
[C]: in function 'dofile'
[string "_RESULT={dofile("donkey.lua")}"]:1: in main chunk
[C]: in function 'xpcall'
/home/leo/torch/install/share/lua/5.1/trepl/init.lua:651: in function 'repl'
...leo/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
[C]: at 0x00406670
I don't know what to do. Thanks for helping.
You need to run opts.lua before running donkey.lua using
th> dofile("opts.lua")
Check main.lua and make sure, you are not missing any other dependencies.

Missing functions in Table Library in Lua

When I run table.maxn() or table.getn() in Lua I get the errors below:
> table.maxn(a)
stdin:1: attempt to call a nil value (field 'maxn')
stack traceback:
stdin:1: in main chunk
[C]: in ?
> table.getn(a)
stdin:1: attempt to call a nil value (field 'getn')
stack traceback:
stdin:1: in main chunk
[C]: in ?
When I try to explore the contents of the table object I get the results below. It is almost as though some functions are missing from the library.
> for k,v in pairs(table) do
>> print (k)
>> end
remove
insert
move
sort
concat
unpack
pack
>
I am using Lua5.3 - from downloaded win32 binaries > Lua53.exe
I have confirmed that I did not alter / affect the table object in any way. The results above were obtained after restarting the Interpreter afresh.
What could the issue be?
You are using lua 5.3 but:
table.getn was deprecated in lua 5.1 (ref)
table.maxn was deprecated in lua 5.2 (ref)
You need to write valid code for the version of lua you are targetting.

Resources