lua 笔记

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动态库:
#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支持:
http://stackoverflow.com/questions/2497800/does-lua-support-unicode
download slnunicode and build ( http://luaforge.net/projects/sln/

猜你喜欢

转载自huaxiamian.iteye.com/blog/2259226