lua 笔记
程序员文章站
2024-03-17 23:49:34
...
1. LuaSocket library, developed by Diego Nehab
2. linux 查看 *.a *.so 符号表
objdump -tT libName.so | grep symbel symbolName
nm -D libName.so | grep symbel symbolName
lua调用C动态库:
编译:
gcc -shared -fPIC luascrlib.c -o luascrlib.so -I /usr/local/luajit/include/luajit-2.0/
拷贝动态库:
sudo cp /home/kevin/lua_files/luascrlib.so /usr/local/lib/lua/5.1/
lua代码执行:
lua unicode支持:
[url]http://*.com/questions/2497800/does-lua-support-unicode[/url]
download slnunicode and build ([url]http://luaforge.net/projects/sln/[/url])
2. linux 查看 *.a *.so 符号表
objdump -tT libName.so | grep symbel symbolName
nm -D libName.so | grep symbel symbolName
lua调用C动态库:
#include <lua.h>
#include <string.h>
#include <lauxlib.h>
#include <lualib.h>
#include <stdlib.h>
#include <stdio.h>
int GetFeature(lua_State *L)
{
// string img =
size_t l;
const char * img = luaL_checklstring(L, 1, &l);
//printf("%zu", l);
const char *feature = "feature1";
lua_pushstring(L, feature);
return 1;
}
static luaL_Reg luascrlibs[] = {
{"GetFeature", GetFeature},
{NULL, NULL}
};
int luaopen_luascrlib(lua_State* L)
{
const char * libName = "luascrlib";
luaL_register(L, libName, luascrlibs);
return 1;
}
编译:
gcc -shared -fPIC luascrlib.c -o luascrlib.so -I /usr/local/luajit/include/luajit-2.0/
拷贝动态库:
sudo cp /home/kevin/lua_files/luascrlib.so /usr/local/lib/lua/5.1/
lua代码执行:
>require "luascrlib"
>print(luascrlib.GetFeature("Hello Wold"))
>feature1
lua unicode支持:
[url]http://*.com/questions/2497800/does-lua-support-unicode[/url]
download slnunicode and build ([url]http://luaforge.net/projects/sln/[/url])