Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ https://github.com/katono/rogue.vim

## Requirements

rogue.vim requires Lua-enabled Vim.
Check `:echo has('lua')` returns 1 and `:echo luaeval('_VERSION')` returns `Lua 5.1` or later.
rogue.vim requires Lua-enabled Vim or neovim.
Please make sure that at least one of the following conditions is met.

- `:echo has('lua')` returns 1 and `:echo luaeval('_VERSION')` returns `Lua 5.1` or later.
- `:echo has('nvim')` returns 1 and `:echo luaeval('_VERSION')` returns `Lua 5.1` or later.

LuaJIT is recommended because that is very fast.

Expand Down
16 changes: 8 additions & 8 deletions autoload/rogue/curses.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ end

function g.refresh()
if vim then
vim.command("normal gg")
g.vim_command("normal gg")
end
local update = false
local done_redraw = false
Expand All @@ -87,17 +87,17 @@ function g.refresh()
row_str = dungeon_row(i):sub(1, dungeon_str_buffer[i].col)
end
if vim then
if i == g.DROWS-1 and vim.eval("&lines") == g.DROWS then
if i == g.DROWS-1 and g.vim_eval("&lines") == g.DROWS then
row_str = row_str .. dungeon_str_buffer[i].str
if g.update_flag or row_str ~= last_print_area then
vim.command("redraw")
print((vim.eval("has('gui_running')") ~= 0 and '' or ' ') .. row_str)
vim.command("redrawstatus")
g.vim_command("redraw")
print((g.vim_eval("has('gui_running')") ~= 0 and '' or ' ') .. row_str)
g.vim_command("redrawstatus")
last_print_area = row_str
done_redraw = true
end
else
if g.update_flag and i == 0 and vim.eval("&lines") > g.DROWS then
if g.update_flag and i == 0 and g.vim_eval("&lines") > g.DROWS then
print(' ')
end
if dungeon_str_buffer[i].str ~= '' then
Expand All @@ -111,7 +111,7 @@ function g.refresh()
if g.update_flag or row_str ~= last_row_str[i] then
local cmd_str
cmd_str = 'call setline(' .. tostring(i + 1) .. ', "' .. row_str .. '")'
vim.command(cmd_str)
g.vim_command(cmd_str)
last_row_str[i] = row_str
update = true
end
Expand All @@ -124,6 +124,6 @@ function g.refresh()
end
g.update_flag = false
if update and not done_redraw then
vim.command("redraw")
g.vim_command("redraw")
end
end
4 changes: 2 additions & 2 deletions autoload/rogue/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function g.msgbox(fmt, ...)
if not g.DEBUG or not vim then
return
end
vim.eval("confirm('" .. string.format(fmt, ...) .. "')")
g.vim_eval("confirm('" .. string.format(fmt, ...) .. "')")
end

function g.log(fmt, ...)
Expand Down Expand Up @@ -178,7 +178,7 @@ function g.breakpoint(log_flag)
local level = 2
local prompt = '\n'..g.__FILE_LINE__(level)..'\n'..'Breakpoint: '
while true do
local input = vim.eval('input("'..prompt..'", "", "tag")')
local input = g.vim_eval('input("'..prompt..'", "", "tag")')
if input == '' then
break
end
Expand Down
2 changes: 1 addition & 1 deletion autoload/rogue/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ local function set_nick_name()
end
local default_name = g.mesg[542]
if vim then
g.nick_name = vim.eval('inputdialog("'..g.mesg[13]..' ", "'..default_name..'")')
g.nick_name = g.vim_eval('inputdialog("'..g.mesg[13]..' ", "'..default_name..'")')
if g.nick_name == '' then
g.nick_name = default_name
end
Expand Down
14 changes: 7 additions & 7 deletions autoload/rogue/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end
Rogue = {}
local g = Rogue -- alias

g.version = '1.0.2'
g.version = '1.0.3'

-- Checks added global data is Rogue only
local function check_global()
Expand Down Expand Up @@ -38,9 +38,9 @@ local function init_dirs()
g.game_dir = g.game_dir:gsub('\\', '/')
g.game_dir = g.game_dir:gsub('~', g.home_dir)
if vim then
local exists = vim.eval('isdirectory("' .. g.game_dir .. '")')
local exists = g.vim_eval('isdirectory("' .. g.game_dir .. '")')
if exists == 0 then
vim.command('call mkdir("' .. g.game_dir .. '", "p")')
g.vim_command('call mkdir("' .. g.game_dir .. '", "p")')
end
end
end
Expand Down Expand Up @@ -118,11 +118,11 @@ local function read_mesg()
local needs_iconv = g.get_vim_variable("s:needs_iconv")
if needs_iconv ~= 0 then
g.needs_iconv = true
vim.command('let &encoding = "utf-8"')
g.vim_command('let &encoding = "utf-8"')
for k, v in pairs(g.mesg) do
g.mesg[k] = g.iconv_from_utf8(v)
end
vim.command('let &encoding = s:save_encoding')
g.vim_command('let &encoding = s:save_encoding')
end
end
return true
Expand All @@ -134,8 +134,8 @@ local function main()
return
end
if vim then
if vim.eval("&columns") < g.DCOLS or vim.eval("&lines") < g.DROWS then
vim.eval('confirm("' .. g.mesg[14] .. '")')
if g.vim_eval("&columns") < g.DCOLS or g.vim_eval("&lines") < g.DROWS then
g.vim_eval('confirm("' .. g.mesg[14] .. '")')
return
end
end
Expand Down
4 changes: 4 additions & 0 deletions autoload/rogue/mesg
Original file line number Diff line number Diff line change
Expand Up @@ -725,3 +725,7 @@ do_args()
file: rogue.vim
rogue#rogue#main
544 "ゲームが中断されています。再開しますか?" "The game is suspended. Resume it?"

file: play.lua
doshell()
545 ":sh コマンドはサポートされていません" ":sh command is not supported"
4 changes: 4 additions & 0 deletions autoload/rogue/mesg_E
Original file line number Diff line number Diff line change
Expand Up @@ -724,3 +724,7 @@ do_args()
file: rogue.vim
rogue#rogue#main
544 "The game is suspended. Resume it?" "ゲームが中断されています。再開しますか?"

file: play.lua
doshell()
545 ":sh command is not supported" ":sh コマンドはサポートされていません"
10 changes: 4 additions & 6 deletions autoload/rogue/message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end
function g.rgetchar()
local n
if vim then
n = vim.eval("getchar()")
n = g.vim_eval("getchar()")
else
os.execute("stty -echo cbreak")
n = string.byte(io.stdin:read(1))
Expand All @@ -29,7 +29,7 @@ function g.rgetchar()
local c = ''
if type(n) == 'string' then
if vim then
if n == vim.eval('"\\<BS>"') then
if n == g.vim_eval('"\\<BS>"') then
c = 'BS'
end
end
Expand All @@ -44,7 +44,7 @@ function g.rgetchar()
end
else
if vim then
c = vim.eval("nr2char("..tostring(n)..")")
c = g.vim_eval("nr2char("..tostring(n)..")")
elseif n <= 0x7E then
c = string.char(n)
end
Expand Down Expand Up @@ -205,7 +205,5 @@ function g.clear_stats()
end

function g.sound_bell()
if vim then
vim.beep()
end
g.vim_beep()
end
7 changes: 6 additions & 1 deletion autoload/rogue/play.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ end

local function doshell()
if vim then
vim.command("sh")
if g.vim_eval("exists(':shell')") == 0 then
-- :shell command is removed in neovim.
g.message(g.mesg[545])
else
g.vim_command("sh")
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion autoload/rogue/rogue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
let s:FILE_DIR = fnamemodify(expand("<sfile>"), ':h') . '/'
let s:FILE_DIR = substitute(s:FILE_DIR, '\\', '/', 'g')
function! rogue#rogue#main(args)
if !has('lua')
if !has('lua') && !(has('nvim') && exists('*luaeval') && luaeval('vim.api ~= nil'))
echo "Sorry. Rogue.vim needs '+lua'."
return
endif
Expand Down
4 changes: 2 additions & 2 deletions autoload/rogue/save.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ function g.restore(fname)
end
g.xxx(true)
buf = g.xxxx(buf)
vim.command('let &encoding = "utf-8"')
g.vim_command('let &encoding = "utf-8"')
buf = g.iconv_from_utf8(buf)
vim.command('let &encoding = s:save_encoding')
g.vim_command('let &encoding = s:save_encoding')
local Rogue_copy = assert(g.loadstring('return ' .. buf), g.mesg[508])()

if g.home_dir ~= Rogue_copy.home_dir then
Expand Down
4 changes: 2 additions & 2 deletions autoload/rogue/score.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ function g.put_scores(monster, other)
local buf = fp:read("*a")
g.xxx(true)
buf = g.xxxx(buf)
vim.command('let &encoding = "utf-8"')
g.vim_command('let &encoding = "utf-8"')
buf = g.iconv_from_utf8(buf)
vim.command('let &encoding = s:save_encoding')
g.vim_command('let &encoding = s:save_encoding')
scores = assert(g.loadstring('return ' .. buf), g.mesg[199])()
fp:close()
end
Expand Down
49 changes: 40 additions & 9 deletions autoload/rogue/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,41 @@ else
g.loadstring = loadstring
end

if vim.api then
function g.vim_beep()
vim.api.nvim_command('silent normal! <C-g>')
end
function g.vim_eval(var)
return vim.api.nvim_eval(var)
end
function g.vim_command(cmd)
return vim.api.nvim_command(cmd)
end
elseif vim then
function g.vim_beep()
vim.beep()
end
function g.vim_eval(var)
return vim.eval(var)
end
function g.vim_command(cmd)
return vim.command(cmd)
end
else
function g.vim_beep()
end
function g.vim_eval(var)
return nil
end
function g.vim_command(var)
return nil
end
end

function g.get_vim_variable(var)
if vim then
if vim.eval("exists('" .. var .. "')") ~= 0 then
return vim.eval(var)
if g.vim_eval("exists('" .. var .. "')") ~= 0 then
return g.vim_eval(var)
end
end
return ''
Expand Down Expand Up @@ -49,9 +80,9 @@ end
function g.set_vim_variable(var, value)
if vim then
if type(value) == 'number' then
vim.command('let ' .. var .. ' = ' .. tostring(value))
g.vim_command('let ' .. var .. ' = ' .. tostring(value))
elseif type(value) == 'string' then
vim.command('let ' .. var .. ' = "' .. value .. '"')
g.vim_command('let ' .. var .. ' = "' .. value .. '"')
end
end
end
Expand Down Expand Up @@ -131,7 +162,7 @@ end
function g.strwidth(s)
local len
if vim then
len = vim.eval('strwidth("' .. s .. '")')
len = g.vim_eval('strwidth("' .. s .. '")')
else
len = #s
end
Expand All @@ -141,7 +172,7 @@ end
function g.getftime(fname)
local t
if vim then
t = vim.eval('getftime("' .. fname .. '")')
t = g.vim_eval('getftime("' .. fname .. '")')
else
t = -1
end
Expand Down Expand Up @@ -169,7 +200,7 @@ end

function g.msleep(n)
if vim then
vim.command('sleep ' .. tostring(n) .. 'm')
g.vim_command('sleep ' .. tostring(n) .. 'm')
end
end

Expand Down Expand Up @@ -198,15 +229,15 @@ end
function g.iconv_from_utf8(str)
if g.needs_iconv then
str = str:gsub("'", "''")
str = vim.eval("iconv('" .. str .. "', 'utf-8', s:save_encoding)")
str = g.vim_eval("iconv('" .. str .. "', 'utf-8', s:save_encoding)")
end
return str
end

function g.iconv_to_utf8(str)
if g.needs_iconv then
str = str:gsub("'", "''")
str = vim.eval("iconv('" .. str .. "', s:save_encoding, 'utf-8')")
str = g.vim_eval("iconv('" .. str .. "', s:save_encoding, 'utf-8')")
end
return str
end
2 changes: 1 addition & 1 deletion doc/rogue.jax
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*rogue.txt* データ分離版ローグ・クローンIIの移植

Version: 1.0.2
Version: 1.0.3
Author: KATO Noriaki <[email protected]>
License: MIT License

Expand Down
2 changes: 1 addition & 1 deletion doc/rogue.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*rogue.txt* Porting of Rogue-clone II for Vim

Version: 1.0.2
Version: 1.0.3
Author: KATO Noriaki <[email protected]>
License: MIT License

Expand Down