Skip to content

Instantly share code, notes, and snippets.

@Akagi201
Last active May 17, 2016 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akagi201/6cce2bd39ab7a0cdce4a to your computer and use it in GitHub Desktop.
Save Akagi201/6cce2bd39ab7a0cdce4a to your computer and use it in GitHub Desktop.

nosql

匿名函数

(function()
    print(1)
    if true then
    	return
    end
    print(2)
end)()


function f()
	a = 1
	function f1()
		print(a)
	end
	f1()
end

f()

源码结构

-- require 其他的模块
-- local ngx_lua 相关的 api
-- local lua 相关的函数(再把 lua 相关的独立出来)

local utils = require "modules.utils"
local metadata = require "modules.metadata"
local cjson = require "cjson.safe"

local get_method = ngx.req.get_method
local get_uri_args = ngx.req.get_uri_args

local null = utils.null

local str_gsub = string.gsub

redis

三元运算符

  • <if-statement> and <true_result> or <false_result>

定位使用全局变量的地方

多版本管理

web server

code style

lua package manager

  • LuaDist
  • LuaRocks

luajit第三方包汇总

json

APIs

  • lua_xxx 主要是 lua 基本 API
  • luaL 是封装过的基本 API

tutorial

sublime text config

  1. build: Tools -> Build System -> New build System, 主要lua要用绝对路径否则找不到.
{
  "cmd": ["/usr/local/bin/lua", "$file"],
  "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
  "selector": "source.lua"
}

只能用于build, 不能传参数, 相当于lua [filename.lua].

install

  • brew install lua luajit metalua luarocks
  • luarocks install luasocket

tool

IDE

lib

lua as config file

Refs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment