使用C语言扩展lua语言功能
2017-11-13 10:55
441 查看
lua是openresty(nginx+lua)中重要的部分,当原生lua满足不了需求时,便需要用C语言对lua进行扩展,比如下面我写了自己的时间模块
将这个文件编译成动态链接库的a.so文件,最后在lua上调用它
#include <stdio.h> #include <stdlib.h> #include <sys/timeb.h> #include <lua_openresty/lua.h> #include <lua_openresty/lauxlib.h> #include <lua_openresty/lualib.h> static int l_yourownname(lua_State *L) { ...这里写自己的代码 } static const struct luaL_Reg yourownname2[] = { {"yourownname", l_yourownname}, {NULL, NULL} }; extern int luaopen_yourownname3(lua_State* L) { luaL_newlib(L,yourownname2);return 1; }
将这个文件编译成动态链接库的a.so文件,最后在lua上调用它
local a = require "a"; local des = libencode.yourownname(); print(des)
相关文章推荐
- 玩转 Nginx 之:使用 Lua 扩展 Nginx 功能
- Ethereal 也可以使用lua做一些自定义的功能了--编写lua脚本扩展ethereal的功能
- 使用lua扩展nginx的功能
- 玩转 Nginx 之:使用 Lua 扩展 Nginx 功能
- 玩转 Nginx 之:使用 Lua 扩展 Nginx 功能
- 汇编语言与C语言的混合使用
- 使用插件功能扩展VB ::来自applevb
- 让主程序可以通过python脚本扩展功能及boost.python的使用
- 汇编语言与C语言的混合使用
- 使用插件功能扩展VB
- ★PHP V5.2 中的新增功能,第 2 部分: 使用新输入过滤扩展
- 在vista下使用加载项扩展IE7的功能
- 用C语言扩展Python的功能的实例
- 用C语言扩展Python的功能
- 使用C来扩展python功能
- 如何使用Lua扩展C/C++应用系列1-转自bbs.luachina.net
- 使用C#的Partial特性进行功能扩展
- 如何使用Lua扩展C/C++应用系列1
- 使用服务器端 Toolkit 扩展 Sametime 服务器功能
- 使用Python语言设计基于HTML的C语言语法加亮显示程序