CSV - Lua Module

ftcsv ์ถ”์ฒœ

2022-11-07 ยท 2 words

LuaFun - LuaJit Functional

Intro LuaFun ์ •์˜ - LuaJit Hight Performance Functional Programming Library luajit์˜ ๋‚ด์žฅํ•จ์ˆ˜๋ฅผ ํ™•์žฅํ•˜์—ฌ ๋‹ค์–‘ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๋•๋Š”๋‹ค. ํ•˜๋‚˜์”ฉ ๊ณต๋ถ€ํ•ด์„œ ํ™œ์šฉํ•˜๋ฉด ๋งค์šฐ ๊ฐ•๋ ฅํ•œ ํˆด์ด ๋  ๊ฒƒ์ด๋‹ค. Usage ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ• $ git clone https://github.com/luafun/luafun.git $ cd luafun $ luajit -i > -- Functional style > require "fun" () > -- calculate sum(x for x^2 in 1..n) > n = 100 > print(reduce(operator.add, 0, map(function(x) return x^2 end, range(n)))) 328350 > -- Object-oriented style > local fun = require "fun" > -- calculate sum(x for x^2 in 1..n) > print(fun.range(n):map(function(x) return x^2 end):reduce(operator.add, 0)) 328350 Using the Library Links github https://github.com/luafun/luafun Document https://luafun.github.io/

2022-10-12 ยท 99 words

Lfs-ffi - LuaJit FFI Lua File System

Intro luaJit์šฉ Lua File System ๋ชจ๋“ˆ ffi๋ฅผ ์ด์šฉํ•œ lfs์ด๋ฉฐ lua์˜ lfs ๋ชจ๋“ˆ๊ณผ ๋˜‘๊ฐ™๋‹ค. ํŒŒ์ผ์‹œ์Šคํ…œ์„ ๋‹ค๋ฃจ๋Š” ํ™•์žฅ ๋ชจ๋“ˆ์ด๋‹ค. ๋ฆฌ๋ˆ…์Šค ์ „์šฉ์ด๋‹ค. ์œˆ๋„์šฐ์ฆˆ์šฉ์€ ์•„๋ž˜ ๊นƒํ—ˆ๋ธŒ์— ๊ฐ€๋ฉด ์•ˆ๋‚ด๊ฐ€ ์žˆ๋‹ค. ์„ค์น˜ luarocks๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์ง์ ‘ ๋‹ค์šด๋กœ๋“œํ•˜์—ฌ ์‚ฌ์šฉ Links Github https://github.com/spacewander/luafilesystem

2022-10-12 ยท 34 words

Lua - Interactive Mode

2023-08-11: rlwarp + readline์„ ํ™œ์šฉํ•œ ํ‚ค์›Œ๋“œ ์™„์„ฑ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ Intro ์ฝ”๋”ฉ์„ ํ•˜๊ธฐ ์ „ ๋˜๋Š” ๋น ๋ฅธ ํ™•์ธ์„ ์œ„ํ•ด ์ธํ„ฐ์—‘ํ‹ฐ๋ธŒ ๋ชจ๋“œ๋ฅผ ์‚ฌ์šฉ ๊ฐ„๋‹จํ•œ ํ…Œ์ŠคํŠธ๋‚˜ ๋ช‡๊ฐ€์ง€ ์‹คํ—˜์„ ํ•ด๋ณด๋Š” ์šฉ๋„๋กœ์„œ ์ข‹๋‹ค. ilua๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด jupyter console, notebook ๋“ฑ์œผ๋กœ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๋‹ค. Execute String $ lua -e 'print("hello world")' hello world Interactive Mode lua -i ๋˜๋Š” luajit -i ๋กœ interactive mode๋กœ ์ง„์ž… -i ์˜ต์…˜์ด ์—†์–ด๋„ ์ง„์ž… ๊ฐ€๋Šฅ local ๋ณ€์ˆ˜๊ฐ€ ๋‹ค์Œ ๋ผ์ธ์—์„œ ์ธ์‹๋˜์ง€ ์•Š๋Š”๋‹ค. ์‚ฌ์šฉํ•  ๋•Œ ์ฃผ์˜ $ lua -i -- ๋˜๋Š” luajit -i > local a = 'hello world' -- local ๋ณ€์ˆ˜ ์„ค์ • > print(a) -- print nil -- ๊ฒฐ๊ณผ: nil > a = 'hello world' -- Global ๋ณ€์ˆ˜ ์„ค์ • > print(a) -- print hello world -- ๊ฒฐ๊ณผ: hello world > os.exit() -- ์ข…๋ฃŒ: ๋˜๋Š” Ctrl+d, Ctrl+c Opening Lua File > f = assert(loadfile('foo.lua') -- luaํŒŒ์ผ ๋กœ๋“œ > f() -- ์‹คํ–‰ > dofile('foo.lua') -- ๋กœ๋“œ ๋ฐ ์‹คํ–‰ > m = require('mymodule') -- mymodule.lua ๋ชจ๋“ˆ ๋กœ๋“œ > m.parse() -- ๋ชจ๋“ˆ๋‚ด ํ•จ์ˆ˜ ์‹คํ–‰ Load Libary Example -- file 'lib1.lua' function norm(x,y) local n2 = x^2 + y^2 return math.sqrt(n2) end function twice(x) return 2*x end > dofile('lib1.lua') -- load your library > n = norm(3.4, 1.0) -- using lib1.lua functions > print(twice(n)) -- using twice functions Command Line Arguments (-- /dev/null ์˜ต์…˜ ์ฃผ๋ชฉ) $ lua -i -- /dev/null one two three > print(arg[1]) -- one > print(arg[2]) -- two > print(arg[3]) -- three > print(arg[0]) -- /dev/null Lua, LuaJit line completion like in bash bash์—์„œ line completion๊ณผ ์œ ์‚ฌํ•œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ rlwrap ํ™œ์šฉ - -a:always-readline,-c:complete-filenames,-e:extra-char-after-completion $ sudo apt install rlwrap $ alias luajit='rlwrap -ac -e "" -pRed luajit' # add this line to ~/.bashrc $ luajit > = 2 + 2 4 > = 2 + 2 --> ํ™”์‚ดํ‚ค๋ฅผ ์ด์šฉํ•˜์—ฌ ์ƒ์œ„ ๋ช…๋ น๋ผ์ธ์„ ๋ถˆ๋Ÿฌ ์˜ฌ ์ˆ˜ ์žˆ๋‹ค. rlwarp์˜ readline์„ ํ™œ์šฉํ•œ ๋ช…๋ น์–ด ์™„์„ฑ: Dictionary ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ์‚ฌ์šฉ. $ echo "print local assert string ..." > ~/.luadict $ alias luajit='rlwrap -b "" -f $HOME/.luadic -pRed -ca -e "" luajit' $ luajit > ass(-> Press Tab Key anc Check) iLua : with Jupyter Jupyter์˜ ๋ง‰๊ฐ•ํ•œ ์ง€์›์•„๋ž˜ ์ฝ˜์†”ํ˜• ์ธํ„ฐ์—‘ํ‹ฐ๋ธŒ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฝ”๋“œ์™„์„ฑ ๋ฐ vi edit mode ๊ทธ๋ฆฌ๊ณ  ๋ณ€์ˆ˜๋ฅผ ์ง์ ‘ ์ถœ๋ ฅ๊ฐ€๋Šฅํ•˜๋‹ค. ๋ฌผ๋ก  ํŠน์„ฑ์ƒ local ๋ณ€์ˆ˜๋Š” ์—ญ์‹œ ์ง€์›๋˜์ง€ ์•Š๋Š”๋‹ค. ํ˜„์žฌ๋กœ์„œ๋Š” ๊ทธ๋ ‡๋‹ค. ~/.local ์ดํ•˜์— jupyter ๋ฐ ilua๊ฐ€ ์„ค์น˜๋œ๋‹ค. ์•„๋ž˜์ฒ˜๋Ÿผ vi edit mode๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋”์šฑ ํŽธ๋ฆฌํ•˜๋‹ค. $ pip install ilua $ echo "c.ZMQTerminalInteractiveShell.editing_mode='vi'" > ~/.jupyter/jupyter_console_config.py $ jupyter console -h # help $ jupyter kernelspec list # ๋‚ด์žฅ ์ปค๋„ ์ŠคํŽ™ ํ™•์ธ $ ~/.local/bin/ilua -i lua[jit] # ์‹คํ–‰ $ echo "alias ilua='ilua -i luajit'" >> ~/.bashrc # luajit ์ „์šฉ alias $ source ~/.bashrc $ ilua Links https://www.lua.org/pil/1.1.html https://www.tutorialspoint.com/command-line-arguments-in-lua https://lua-users.org/wiki/InteractiveLua https://github.com/guysv/ilua https://jupyter-console.readthedocs.io/en/latest/config_options.html

2022-09-22 ยท (updated 2023-08-11) ยท 422 words

Love - ๋ฃจ์•„ 2D ๊ฒŒ์ž„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ

Intro love๋Š” lua์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” 2D ๊ฒŒ์ž„ ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค. ๊ฒŒ์ž„์„ ๋งŒ๋“ค๋ ค๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๊ณ  2D ๊ทธ๋ž˜ํ”ฝ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ๋ชจ์ƒ‰ํ•˜๊ธฐ ์œ„ํ•จ. ์ž‘์€ ๋ชจ์˜ ์‹คํ—˜์ด๋‚˜ ์‹œ๋ฎฌ๋ ˆ์ด์…˜์šฉ์œผ๋กœ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ์—ญ์‹œ ์ž‘๊ณ  ๊ฐ€๋ณ๊ณ  ๋น ๋ฅด๋‹ค. Install debian/ubuntu package install $ sudo apt install love # ํŒจํ‚ค์ง€ ์„ค์น˜ $ love --version # check version ubuntu ppa install: ์ตœ์‹ ๋ฒ„์ „์œผ๋กœ ์„ค์น˜ $ sudo add-apt-repository ppa:bartbes/love-stable $ sudo apt update $ sudo apt install love $ love --version Hello World $ mkdir ~/love-test # make dir for love application $ cd ~/love-test # goto dir $ cat <<EOF > main.lua # edit main.lua source file function love.draw() love.graphics.print("Hello World", 400, 300) end EOF $ love . # love <path> : ์‹คํ–‰ OR $ love ~/love-test # ํ”„๋กœ์ ํŠธ ํด๋”๋ช… vim nvim ์ง€์› ํ”Œ๋Ÿฌ๊ทธ์ธ sumneko lua-language-server ๋ฅผ ์„ค์น˜ํ•˜๊ณ  ์„ค์ •ํ•ด ์ฃผ๋ฉด ๋œ๋‹ค. ...

2022-09-15 ยท (updated 2023-01-26) ยท 694 words