LoginSignup
9
11

More than 5 years have passed since last update.

Luaでカレントディレクトリとかファイルシステムの情報を求めたい

Last updated at Posted at 2013-05-14

dirnameとかrealpathとかそんなの使いたい。

Luaには標準でPythonのos.path相当のライブラリは用意されていない。
C APIバインドなライブラリである
luaposixを使おう。

インストール方法

luarocksコマンドでインストールすれば終わり。

> luarocks install luaposix
> lua
> require ("posix")

簡単だ。

使い方

ライブラリのリファレンスはこちら

カレントディレクトリを確認したい

> =posix.getcwd()
/Users/matsuzakikeiji/Sandbox/Lua

リアルパスを取得したい

> =posix.realpath(".")
/Users/matsuzakikeiji/Sandbox/Lua

今後はposixライブラリにお世話になろう。便利である。

ちなみにLuaのコードハイライトがQiitaに用意されていないようだ...
追記:コメントにてLuaは候補では出てこないけどハイライトはできるよと教えていただきました。ご迷惑おかけしました。

9
11
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
11