openresty-lua-types 是利用了TypeScriptToLua 搞一个一个openresty ts 定义,原想是自己搞一个,但是看到社区已经有类似的实现了
值得参考学习下,以下是一个简单的试用
参考代码
- package.json
{
"name": "myopenresty-lua",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"build": "tstl",
"dev": "tstl --watch"
},
"devDependencies": {
"openresty-lua-types": "^1.0.3",
"typescript": "^4.6.3",
"typescript-to-lua": "^1.4.3"
}
}
tsconfig.json
{
"$schema": "https:///TypeScriptToLua/vscode-typescript-to-lua/master/tsconfig-schema.json",
"include": [
"src/*"
],
"compilerOptions": {
"outDir": "./dist",
"target":"ESNext",
"types": ["openresty-lua-types"],
"lib": ["esnext","DOM"],
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"strict": true
},
"tstl": {
"noHeader": true, // 去掉头
"noImplicitSelf":true, // 禁用self
"buildMode": "library",
"luaTarget": "JIT"
}
}
src/myapp.ts
ngx.say("dalongdmo","appdemo")
ngx.exit(ngx.HTTP_OK)
let method = ngx.req.get_method()
if (method === "GET") {
console.log("do get ")
}
自动提示效果
构建效果
说明
基于TypeScriptToLua + openresty-lua-types 开发openresty 模块很好很强大,值得使用