Lua - mode ์ฒ˜๋ฆฌ ํ•จ์ˆ˜

์†Œ๊ฐœ lua์—์„œ mode ์ธ์ž๋ฅผ ๋ฐ›์„ ๋•Œ string, table ๋ชจ๋‘๋ฅผ ๊ตฌ๋ณ„ํ•˜์ง€ ์•Š๊ณ  ์ฒ˜๋ฆฌํ•˜๊ธฐ ์ด๋Š” vim.keymap.set() ํ•จ์ˆ˜์—์„œ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ๋‚ด๋ถ€์—์„œ type์ด table์ด ์•„๋‹ˆ๋ฉด {mode}๋กœ ํƒœ์ด๋ธ”๋กœ ๋ฐ”๊พธ๊ณ  For๋ฌธ์œผ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค. ์˜ˆ์ œ -- ํ•จ์ˆ˜ ์ •์˜ function my_map(mode, short, command, opts) local modes = type(mode) == 'table' and mode or { mode } for _, m in ipairs(modes) do vim.keymap.set(m, short, command, opts) end end -- ์‚ฌ์šฉ my_map('n','<leader>r', ':source %<CR>', {noremap=true}) my_map({ 'n','v' },'<leader>r', ':source %<CR>', {noremap=true})

2025-07-29 ยท 72 words

Luajit - Nvim Lsp Config

์†Œ๊ฐœ ๋ฆฌ๋ˆ…์Šค ํ™˜๊ฒฝ(Alpine Linux)์—์„œ lua-language-server ์„ค์น˜ํ•˜๊ณ  nvim์—์„œ ์„ค์ • ๋ฐ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ•ด ๋ณธ๋‹ค. alpine 3.2x ๊ธฐ์ค€์œผ๋กœ ์„ค๋ช…ํ•œ๋‹ค. ๊ณผ๊ฑฐ alpine ๋ฒ„์ „๋“ค์€ lua-language-server๊ฐ€ ์—†๊ฑฐ๋‚˜ nvim์˜ ๋ฒ„์ „์ด ๋‚ฎ์•„ ํ”Œ๋Ÿฌ๊ทธ์ธ ์ง€์›์— ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค. ํ˜„์žฌ ์‹œ์ ์„ ๊ธฐ์ค€์œผ๋กœ ๋ชจ๋‘ ์ ์ ˆํ•œ ๋ฒ„์ „์„ ์ง€์›ํ•˜๊ณ  ํŒจํ‚ค์ง€๋„ ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์†Œ์Šค ์ปดํŒŒ์ผ ๋“ฑ์˜ ๋ถ€๋‹ด์ด ์—†์–ด์กŒ๋‹ค. ์„ค์น˜ luajit๋ฐ lua-language-server ๊ทธ๋ฆฌ๊ณ  neovim๊ด€๋ จ ํŒจํ‚ค์ง€ ์„ค์น˜ ์•„๋ž˜์˜ ๊ฒฝ์šฐ nvim(neovim) ์„ค์น˜์‹œ lfs.so,penlight๋“ฑ์ด ๊ธฐ๋ณธ ํฌํ•จํ•˜๊ฒŒ ๋œ๋‹ค. (์ถ”๊ฐ€ ์„ค์น˜ ๋ถˆํ•„์š”) apk add --no-cache luajit luajit-dev lua-language-server ldoc apk add --no-cache neovim neovim-doc nvim-treesitter \ tree-sitter tree-sitter-cli tree-sitter-lua tree-sitter-bash \ tree-sitter-c tree-sitter-markdown tree-sitter-vimdoc ์„ค์ • ~/.config/nvim/init.lua์— ๋‹ค์Œ ์„ค์ •์„ ์ถ”๊ฐ€ my_project_path๋Š” ๊ฐœ๋ณ„ ๋ชจ๋“ˆ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒฝ์šฐ์ด๋‹ค. workspace์˜ library ๋ฒ”์œ„๊ฐ€ ํฌ๋ฉด ๋ถ€ํ•˜๊ฐ€ ์ปค์ง€๋ฏ€๋กœ ์ ๋‹นํžˆ ์กฐ์ ˆํ•ด ์ฃผ์–ด์•ผ nvim์—์„œ ๋ฌด๋ฆฌ๊ฐ€ ์—†๋‹ค. ์•„๋ž˜ ์ฃผ์„ ํ‘œ์‹œ๋œ ๋ถ€๋ถ„์„ ์ฃผ์˜ํ•ด์„œ ํ™•์ธํ•˜๊ณ  ์ž์‹ ์—๊ฒŒ ๋งž๋Š” ํ™˜๊ฒฝ์„ ์„ค์ •ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ณผ๊ฑฐ sumneko๋ผ๋Š” ์‹์œผ๋กœ ์„ค์ •ํ–ˆ๋Š”๋ฐ ํ˜„์žฌ lspconfig.lua_ls.setup์œผ๋กœ ๋ฐ”๋€Œ์—ˆ๋‹ค. -- Now set capabilities on your LSP servers local lspconfig = require'lspconfig' local my_project_path = os.getenv('HOME') .. '/.local/lib/lua' print(my_project_path) lspconfig.lua_ls.setup { --capabilities = capabilities, root_dir = lspconfig.util.root_pattern(".git", ".luarc.json", ".luarc.js"), settings = { Lua = { runtime = { version = 'Luajit', path = vim.split(package.path, ";"), }, diagnostics = { globals = {'vim'}, update_in_insert = false, }, workspace = { library = { --// ๊ธฐ๋ณธ vim ๋Ÿฐํƒ€์ž„ ํ™˜๊ฒฝ ๋ชจ๋“ˆ ์ถ”๊ฐ€ [vim.env.VIMRUNTIME] = true, --// ๋ชจ๋“  vim์˜ ๋Ÿฐํƒ€์ž„ ํ™˜๊ฒฝ ๋ชจ๋“ˆ ์ถ”๊ฐ€ --[vim.api.nvim_get_runtime_file("", true)] = true, --// my project ๋ชจ๋“ˆ ์ถ”๊ฐ€ [vim.fn.expand(my_project_path)] = true, }, --// ์ œ3์˜ ๋ชจ๋“ˆ ์ œ์™ธ checkThirdParty = false, }, telemetry = { enable = false, }, }, }, } ์ฐธ๊ณ  lua-language-server - Getting Started https://github.com/sumneko/lua-language-server/wiki/Getting-Started#command-line

2025-07-27 ยท 241 words

Lua Batteries - ๋ฃจ์•„ ๋ฒ ํ„ฐ๋ฆฌ ํ™•์žฅ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

lua - batteries lua ํ™•์žฅ ๋ฒ ํ„ฐ๋ฆฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด ๋ณธ๋‹ค. Lua Fun 2100stars https://github.com/luafun/luafun High-performance functional programming library designed for Luajit 3๋‹ฌ์ „ Basic Functions Generators Slicing Indexing Filtering Reducing Transformations Compositions Operators Moses 634stars https://github.com/Yonaba/Moses Utility library for functional programming in Lua fun๊ณผ ์œ ์‚ฌํ•˜๋‚˜ ๋” ๋งŽ์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ๋Š” ๋“ฏ, moses.lua ํŒŒ์ผ ํ•˜๋‚˜. 6๋…„์ „ Table, Array, Utility, Object, Chaining, Import lua-stdlib 289stars https://github.com/lua-stdlib/lua-stdlib document - https://lua-stdlib.github.io/lua-stdlib/ 8๋…„์ „ modules(std) - debug, functional, io, math, operator, package, strict, string, table Classes - tree, container, object, list, optparse, set, strbuf Microlight 169stars https://github.com/stevedonovan/Microlight ๋ง ๊ทธ๋Œ€๋กœ ๊ฒฝ๋Ÿ‰ penlight, ๋‹ฌ๋ž‘ ml.lua ํŒŒ์ผ ํ•˜๋‚˜ 13๋…„์ „ Strings - tstring, table.concat, table.split, expand, escape Files and Paths - access, exist, readfile, splitpath, splitext Inserting and Extendig - update, extend, insertvalues, import Extracting and Mapping - sub, indexby, imap, indexof, ifind, ifilter, imapfilter, collect, removerange Sets and Maps - indexof, invert, issubset, makemap Higher-order Functions - compose, bind1, bind2 Classes Array Class Experiments Penlight 371stars https://github.com/lunarmodules/Penlight Python์—์„œ ์ œ๊ณตํ•˜๋Š” ์—ฌ๋Ÿฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ์œ ์‚ฌํ•œ ํƒ€์ž…์œผ๋กœ ์ œ๊ณตํ•œ๋‹ค. 3 month ๊ณ„์† ์—…๋ฐ์ดํŠธ ๋ฐ ๊ฐœ์„  Paths, Files and Directories - path, isdir, isfile, exists, dirname, basename - dir, getfiles, getallfiles - file: copy, move, read, write Application Support - app, lapp, config, strict, utils, compat, types Extra String Operations - utils, stringx, stringio, lexer, text, template, sip Extra Table Operations - tablex, pretty, List, Map, Set, OrderMap, data, array2d, permute Iterators, OOP and Functional - seq, class, func, utils, compression Batteries for Lua https://github.com/1bardesign/batteries love์— ํŠนํ™”๋œ ํ™•์žฅ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค. ํ•˜์ง€๋งŒ ๋ฒ”์šฉ์œผ๋กœ ์‚ฌ์šฉํ•ด๋„ ๋ฌธ์ œ ์—†๋‹ค. ๋”๊ตฌ๋‚˜ Penlight๋ณด๋‹ค ๊ฒฝ๋Ÿ‰์ด๊ณ  ๋น ๋ฅด๋‹ค. Lua Core Extensions - mathx, tablex, stringx General Utility - class, functional, sequence, set, sort, state_machine, timer, pubsub, pretty Geometry - intersect, vec2, vec3 Special Interest - async, colour(color), manual_gc, measure, make_pooled

2025-07-18 ยท 283 words

Lua Emoji - ๋ฃจ์•„ ์ด๋ชจ์ง€

์†Œ๊ฐœ ๐Ÿต GPT-4o mini์˜ ์„ค๋ช…์„ ์ธ์šฉํ•œ๋‹ค. ์ด๋ชจ์ง€๋Š” ๊ฐ์ •, ์‚ฌ๋ฌผ, ๋™๋ฌผ, ์Œ์‹, ํ™•๋™ ๋“ฑ์„ ํ‘œํ˜„ํ•˜๋Š” ์ž‘์€ ๊ทธ๋ฆผ ๋ฌธ์ž์ด๋‹ค. ์ฃผ๋กœ ๋””์ง€ํ„ธ ์ปค๋ฎค๋‹ˆ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉ๋˜๋ฉด, ํ…์ŠคํŠธ ๋ฉ”์‹œ์ง€, ์†Œ์…œ ๋ฏธ๋””์–ด, ์ด๋ฉ”์ผ ๋“ฑ์—์„œ ๊ฐ์ •์„ ์ „๋‹ฌํ•˜๊ฑฐ๋‚˜ ๋‚ด์šฉ์„ ๊ฐ•์กฐํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค€๋‹ค. 1. ์—ญ์‚ฌ ์ด๋ชจ์ง€๋Š” 1990๋…„๋Œ€ ์ผ๋ณธ์—์„œ ์ฒ˜์Œ ์‚ฌ์šฉ๋˜์—ˆ์œผ๋ฉฐ, โ€œ์ด๋ชจ์ง€"๋ผ๋Š” ์šฉ์–ด๋Š” ์ผ๋ณธ์–ด๋กœ โ€œ๊ทธ๋ฆผ ๋ฌธ์ž"๋ฅผ ์˜๋ฏธํ•œ๋‹ค. 2010๋…„, ์ด๋ชจ์ง€๋Š” Unicode ํ‘œ์ค€์— ํฌํ•จ๋˜์–ด ์ „ ์„ธ๊ณ„์ ์œผ๋กœ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค. 2. ์ข…๋ฅ˜ ๊ฐ์ • ์ด๋ชจ์ง€: ๐Ÿ˜Š, ๐Ÿ˜‚, ๐Ÿ˜ข ๋“ฑ ๊ฐ์ •์„ ํ‘œํ˜„ํ•˜๋Š” ์ด๋ชจ์ง€. ์‚ฌ๋ฌผ ์ด๋ชจ์ง€: ๐Ÿ“ฑ (ํœด๋Œ€ํฐ), ๐ŸŽ (์‚ฌ๊ณผ) ๋“ฑ ๋ฌผ์ฒด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ด๋ชจ์ง€. ๋™๋ฌผ ์ด๋ชจ์ง€: ๐Ÿถ (๊ฐ•์•„์ง€), ๐Ÿฑ (๊ณ ์–‘์ด) ๋“ฑ ๋™๋ฌผ์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ด๋ชจ์ง€. ์Œ์‹ ์ด๋ชจ์ง€: ๐Ÿ• (ํ”ผ์ž), ๐Ÿฃ (์ดˆ๋ฐฅ) ๋“ฑ ์Œ์‹์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ด๋ชจ์ง€. ํ™œ๋™ ์ด๋ชจ์ง€: โšฝ (์ถ•๊ตฌ๊ณต), ๐ŸŽ‰ (์ถ•ํ•˜) ๋“ฑ ํ™œ๋™์ด๋‚˜ ์ด๋ฒคํŠธ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ด๋ชจ์ง€. 3. ์‚ฌ์šฉ ์ด๋ชจ์ง€๋Š” ๊ฐ์ •์„ ์‹œ๊ฐ์ ์œผ๋กœ ํ‘œํ˜„ํ•˜์—ฌ ํ…์ŠคํŠธ์˜ ์˜๋ฏธ๋ฅผ ๊ฐ•ํ™”ํ•œ๋‹ค. ๋Œ€ํ™”์˜ ๋ถ„์œ„๊ธฐ๋ฅผ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ํ•˜๊ฑฐ๋‚˜, ์œ ๋จธ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. ์ด๋ชจ์ง€๋Š” ๋‹ค์–‘ํ•œ ํ”Œ๋žซํผ๊ณผ ๊ธฐ๊ธฐ์—์„œ ๋™์ผํ•œ ๋ฐฉ์‹์œผ๋กœ ํ‘œ์‹œ๋˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ์ง€๋งŒ, ๊ฐ ํ”Œ๋žซํผ์— ๋”ฐ๋ผ ๋””์ž์ธ์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค. 4. ๋ฌธํ™”์  ์ฐจ์ด ์ด๋ชจ์ง€๋Š” ๋ฌธํ™”์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ํ•ด์„๋  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ํŠน์ • ์ด๋ชจ์ง€๊ฐ€ ํ•œ ๋ฌธํ™”์—์„œ๋Š” ๊ธ์ •์ ์ธ ์˜๋ฏธ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์ง€๋งŒ, ๋‹ค๋ฅธ ๋ฌธํ™”์—์„œ๋Š” ๋ถ€์ •์ ์ธ ์˜๋ฏธ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค. 5. ์ตœ์‹  ๋™ํ–ฅ ์ด๋ชจ์ง€๋Š” ์ง€์†์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ๋˜๊ณ  ์žˆ์œผ๋ฉฐ, ์ƒˆ๋กœ์šด ์ด๋ชจ์ง€๊ฐ€ ๋งค๋…„ ์ถ”๊ฐ€๋œ๋‹ค. Unicode Consortium์€ ์ƒˆ๋กœ์šด ์ด๋ชจ์ง€๋ฅผ ์ œ์•ˆํ•˜๊ณ  ์Šน์ธํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. ์ด๋ชจ์ง€๋Š” ํ˜„๋Œ€ ์ปค๋ฎค๋‹ˆ์ผ€์ด์…˜์—์„œ ์ค‘์š”ํ•œ ์—ญํ• ์„ ํ•˜๋ฉฐ, ์‚ฌ๋žŒ๋“ค ๊ฐ„์˜ ๊ฐ์ •๊ณผ ์ƒ๊ฐ์„ ํšจ๊ณผ์ ์œผ๋กœ ์ „๋‹ฌํ•˜๋Š” ๋„๊ตฌ๋กœ ์ž๋ฆฌ ์žก๊ณ  ์žˆ๋‹ค. ...

2025-06-26 ยท 353 words

Openresty - Scalable Web Platform NGINX with Lua

INTRO openresty๋Š” nginx์™€ lua ๊ธฐ๋ฐ˜์˜ ์›น๊ฐœ๋ฐœ ํ”Œ๋žซํผ์ด๋‹ค. lua๋Š” luajit ์„ ์‚ฌ์šฉํ•˜๊ณ  ์—”์ง„์ด ํฌํ•จ๋˜์–ด ์žˆ๋‹ค. ์„œ๋ฒ„์—์„œ ๋™์ž‘ํ•œ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๋ฆฌ๋ˆ…์Šค ๋ฐฐํฌํŒ์€ ํŒจํ‚ค์ง€๋ฅผ ์ง€์›ํ•œ๋‹ค. ์—ฌ๊ธฐ์—์„œ๋Š” docker ์ด๋ฏธ์ง€๋กœ ์„ค์น˜ํ•˜๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ•œ๋‹ค. System Info: RaspberryPi 3 Model B Rev 1.2 OS: Raspbian (Debian 11, Bullseye) Docker: version 24.0.5 Getting Started Hello World # Install Docker and Relogin after exit curl -sSL https://get.docker.com | sh sudo usermod -aG docker $usermod exit ... docker run hello-world # Docker Image get docker pull openresty/openresty:alpine # Setup mkdir ~/www cd ~/www mkdir conf html vi conf/nginx.conf ... worker_processes 1; error_log error.log; events { worker_connections 1024; } http { server { listen 8000; location / { default_type text/html; content_by_lua ' ngx.say("<p>hello world!</p>") '; } } } ... # Run openresty docker image docker run --name mresty --rm --volume `pwd`/conf/:/usr/local/openresty/nginx/conf/ \ -p 127.0.0.1:8000:8000 openresty/openresty:alpine # docker process check docker ps # openresty web server test curl localhost:8000 <p>hello world!</p> Openresty Comandline Utility # version check resty -v # Hello World resty -e 'print("Hello World")' echo 'print("Hello World")' > hello.lua resty hello.lua # resty ngx module test time resty -e 'gnx.sleep(1) ngx.say("done")' resty -e 'local sock = ngx.socket.tcp() print(socke:connect("openresty.com",443))' resty -e 'ngx.thread.wait(ngx.thread.spawn(function () print("in thread!") end))' mkdir lua/ vim lua/test.lua ... local _M = {} function _M.hello() print("Hello") end return _M ... resty -e 'require "test".hello()' # Error resty -I lua/ -e 'require "test".hello()' # Hello resty -e 'local ok, stdout = require "resty.shell".run([[echo ok]]) print(stdout)' # ok resty --shdict 'dogs 10m' -e 'print(ngx.shared.dogs:set("age",11))' # truenilfalse resty --shdict 'dogs 7m' --shdict 'cats 5m' -e 'print(ngx.shared.dogs, " ", ngx.shared.cats)' resty --http-conf 'lua_regex_match_limit 102400;' -e 'print "ok"' # Bench Test echo 'local a = 0 for 1, 1e8 do a = a+1 end print(a)' > bench.lua time resty -joff bench.lua # without Jit Compiler time resty bench.lua # with Jit Compiler (Fast) resty -jv bench.lua resty -jdump bench.lua | less # Help resty -h | less # See Help restydoc resty-cli # See Document Structure and Lua Module Create Project Folder and Modules mkdir test-module cd test-module mkdir logs conf lua vim lua/hello.lua ... local _M = {} function _M.greet(name) ngx.say("Greetings from ", name) end return _M ... Setup nginx.conf vim conf/nginx.conf ... worker_processes 1; events { worker_connections 1024; } http { # Lua module Preload for performance and Cache init_by_lua_block { require "hello" } # add module path to lua package path: $prefix means nginx -p option value lua_package_path "$prefix/lua/?.lua;;" # Server Setup: port, lua block... server { listen 8080 reuseport; location / { content_by_lua_block { local hello = require "hello" hello.greet("a Lua module") } } } } ... Server start and Test # server configuration test nginx -p $PWD/ -t # server start nginx -p $PWD/ # Chech Error Log tail logs/error.log # client request test : Browser also available curl 'http://127.0.0.1:8080' Greetins from a Lua module Server Admin # check server process ps aux | grep nginx | grep -v /tmp/ pgrep -l nginx # Edit nginx.conf vim conf/nginx.conf # Server Restart (After editting of nginx.conf) kill -HUP `cat logs/nginx.pid` # client request again curl 'http://127.0.0.1:8080' Build Develop Environment Makefile์„ ๋งŒ๋“ค๊ณ  ๋„์ปค์ด๋ฏธ์ง€๋ฅผ ์ œ์–ดํ•˜๊ณ  ๋กœ๊ทธ ๋“ฑ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ํ™˜๊ฒฝ์„ ๋งŒ๋“ ๋‹ค. Makefile conf/nginx.conf Test REFERENCE awesome-resty - https://github.com/bungle/awesome-resty ...

2023-09-16 ยท (updated 2023-09-27) ยท 566 words