I tried to use this simple script (its not from me) for simple reading a file and adding its content to a plugin called projectionist: https://github.com/tpope/vim-projectionist
(The original script: https://github.com/andyl/vim-projectionist-elixir/blob/master/ftdetect/elixir.vim)
I didn't find any api for reading a file in lua nvim. The error in the picture targets the line let l:json = readfile(s:proj_jsn) so I assume that this api is not available by lua?
if vim.g.loaded_vim_projectionist then
return
end
vim.g.loaded_vim_projectionist = 1
vim.api.nvim_exec([[
let s:base_dir = resolve(expand("<sfile>:p:h"))
let s:proj_jsn = s:base_dir . "/projections.json"
function! s:setProjections()
let l:json = readfile(s:proj_jsn)
let l:dict = projectionist#json_parse(l:json)
call projectionist#append(getcwd(), l:dict)
endfunction
call s:setProjections()
]], false)
The error message (picture)
I checked a several times if the file projections.json is in the right place, so this is not the mistake.
Thank you all in advance.
Related
I am new to vim and esp. in lua scripting. I want to create an autocmd such that all the jinja files will get yaml syntax highlighting.
local a = vim.api
a.nvim_create_autocmd( { "BufNewFile", "BufRead" }, {
pattern = { "*.j2" },
command = [[ lua(syntax = "html")]],
})
but this is not working. Could someone point the obvious.
DD.
I give you an Example on how i do Lua Syntaxhighlightning for my own *.luado files.
Before i have copied ( as super Q User: root.root ) /usr/share/nvim/runtime/syntax/lua.vim to /usr/share/nvim/runtime/syntax/luado.vim.
So i can change it independently from original lua.vim.
It is not necessary to change luado.vim for the Example below.
~/.config/nvim/lua/init.lua required by ~/.config/nvim/init.vim
( At First and off course before: syntax on )
--[[ Automatic Execution of Lua Oneliner if file extension *.luado
With Lua Syntaxhighlighting ]]
vim.api.nvim_create_autocmd({"BufEnter"},{
pattern = {"*.luado"},
command = "luado vim.api.nvim_command('setfiletype luado') load(line, 'koys_nvim_auto_luado')()"
})
Triggers at "BufEnter" and shows that "BufNewFile", "BufRead" not really needed.
( Every time before it is shown from Buffer ;-) )
Impression
Now lets change to next Buffer with :bn to test3.luado
And back with :bp to test2.luado (Output of set)
(test2.luado will be shown after ENTER/RETURN)
I would like to configure neovim (0.7.0) with lua, without plugins.
I've configured line number via vim.wo.number = true. I guess it would similarly works if I use vim.o.statusline = "%F" to let the statusline show file name / path.
However, my neovim's statusline is still empty. How can I change my init.lua, to let the statusline show filepath?
Currently the init.lua is:
vim.wo.number = true
vim.o.smarttab = true
vim.bo.expandtab = true
vim.bo.shiftwidth = 4
vim.bo.tabstop = 4
vim.o.statusline = "%F"
vim.wo.statusline = '%F'
vim.o.laststatus = 2
According to :help
The value of this option influences when the last window will have a
status line:
0: never
1: only if there are at least two windows
2: always
The screen looks nicer with a status line if you have several
windows, but it takes another screen line. status-line
This code is for a modding engine, Unitale base on Unity Written in Lua
So I am trying to use a Boolean Variable in my script poseur.lua, so when certain conditions are met so I can pass it to the other script encounter.lua, where a engine Predefined functions is being uses to make actions happens base on the occurring moment.
I tried to read the engine documentation multiple times, follow the exact syntax of Lua's fonction like GetVar(), SetVar(), SetGobal(),GetGlobal().
Searching and google thing about the Language, post on the subreddit and Game Exchange and tried to solve it by myself for hours... I just can't do it and I can't understand why ?
I will show parts of my codes for each.
poseur:
-- A basic monster script skeleton you can copy and modify for your own creations.
comments = {"Smells like the work\rof an enemy stand.",
"Nidhogg_Warrior is posing like his\rlife depends on it.",
"Nidhogg_Warrior's limbs shouldn't\rbe moving in this way."}
commands = {"GREET", "JUMP", "FLIRT", "CRINGE"}
EndDialougue = {" ! ! !","ouiii"}
sprite = "poseur" --Always PNG. Extension is added automatically.
name = "Nidhogg_Warrior"
hp = 99
atk = 1
def = 1
check = "The Nidhogg_Warrior is\rsearching for the Nidhogg"
dialogbubble = "rightlarge" -- See documentation for what bubbles you have available.
canspare = false
cancheck = true
GreetCounter = 5
Berserk = false
encounter:
-- A basic encounter script skeleton you can copy and modify for your own creations.
encountertext = "Nidhogg_Warrior is\rrunning frantically"
nextwaves = {"bullettest_chaserorb"}
wavetimer = 5.0
arenasize = {155, 130}
music = "musAncientGuardian"
enemies = {"poseur"}
require("Monsters.poseur")
enemypositions = {{0, 0}}
-- A custom list with attacks to choose from.
-- Actual selection happens in EnemyDialogueEnding().
-- Put here in case you want to use it.
possible_attacks = {"bullettest_bouncy", "bullettest_chaserorb", "bullettest_touhou"}
function EncounterStarting()
-- If you want to change the game state immediately, this is the place.
Player.lv = 20
Player.hp = 99
Player.name = "Teemies"
poseur.GetVar("Berserk")
end
Thank you for reading.
The answer to my problem was to use SetGobal(), GetGobal().
For some reasons my previous attempt to simply use SetGobal()Resulted in nil value despite writing it like that SetGobal("Berserk",true) gave me a nill value error, as soon as I launch the game.
But I still used them wrong. First I needed to put it SetGobal() at the end of the condition instead of at the start of the the poseur.lua script because the change of value... for some reasons was being overwritten by it first installment.
And to test the variable in the function in my encounter.lua, I needed to write it like that
function EnemyDialogueStarting()
-- Good location for setting monster dialogue depending on how the battle is going.
if GetGlobal("Jimmies") == true then
TEEEST()
end
end
Also any tips an suggestions are still welcome !
Well firstly, in lua simple values like bool and number are copied on assignment:
global={}
a=2
global.a=a--this is a copy
a=4--this change won't affect value in table
print(global.a)--2
print(a)--4
Secondly,
SetGobal and the other mentioned functions are not part of lua language, they must be related to your engine. Probably, they use word 'Global' not as lua 'global' but in a sense defined by engine.
Depending on the engine specifics these functions might as well do a deep copy of any variable they're given (or might as well not work with complicated objects).
I'm trying to write a script for DC++ hub based on Ptokax running on lua
i'm trying to assign the nick(a variable) which has punctuation in between but it gives nil values
(sPattern is ! already assigned in script)
sData = "[11:03:30] !spm sTo_Nick sFromNick message to be sent"
cmd,sToNick1,sToNick2,sFromNick ,sMessage = string.match(sData, "%b<>%s["..sPattern.."](%a*)(%s+)(%w*)(%s+)(%w*)(%s+)(%.*)")
what i want to be assigned is
cmd = spm
sToNick1 = sTo ,
sToNick2 = Nick ,
sFromNick = sFromNick ,
sMessage = message to be sent
what i'm getting is
spm sTo _ Nick
as can be seen here https://repl.it/BrAg/3
can anyone please suggest the edit or help.
You need to rearrange the capture groups:
cmd,sToNick1,sToNick2,sFromNick,sMessage =
string.match(sData, "%b<>%s["..sPattern.."](%a*)%s+(%w*)"..pattern.."(%w*)%s+(%w*)%s+(.*)")
See the updated demo
I am just starting writing scripts for Foldit. This is my first experience of Lua, so my status is "noob with insight". In my first script, I want to print out contactmap data. I have copied and pasted the functions from http://foldit.wikia.com/wiki/Foldit_Lua_Functions. The error I get is:
attempt to index global 'structure' (a nil value)
Here is my code:
segmentCount = structure.GetCount()
print ("Segment count: " .. segmentCount)
for source = 1, segmentCount do
for target = source + 1, segmentCount do
inContact = contactmap.IsContact(source, target)
heat = contactmap.GetHeat(source, target)
print("Segments "..source..", ".. target..": heat = "..heat)
end
end
Thanks in advance for any enlightenment.
EDIT
The problem was that I had originally loaded a V1 recipe, and foldit continued to treat it as V1 syntax. The solution was to create a New (ScriptV2) recipe, and load exactly the same code.
You seem to be doing everything according to the documentation. The error means that contactmap is not defined (has nil value) and the code fails on accessing its elements. I'd check the version of Foldit you are using as the documentation says that contactmap is new in version 2.