openresty-lua-types openresty typescript 类型定义

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://raw.githubusercontent.com/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 模块很好很强大,值得使用

参考资料

https://github.com/TypeScriptToLua/TypeScriptToLua
https://github.com/andrei-markeev/openresty-lua-types
https://github.com/openresty/lua-nginx-module
https://www.npmjs.com/package/openresty-lua-types

posted on   荣锋亮  阅读(54)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-04-17 streamsets http client 请求过大问题
2021-04-17 使用graalvm 运行cube.js
2021-04-17 使用presto-gateway 进行trino 扩展
2021-04-17 trino 兼容presto 的方法
2020-04-17 ff4j 特性开关功能开发的一些实践理论
2020-04-17 java 几个不错的特性开关框架
2018-04-17 k8s helm 私服chartmuseum minio s3 存储配置

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示