lua和c语言之间的互调大量出现在lua-nginx-module中,这里给出《lua程序设计》第24-27章的一些测试代码。
#include #include #include #include #include #include #include #include #define max_color 255static void stackdump(lua_state *l);static int l_split(lua_state *l){ const char *s = lual_checkstring(l, 1); const char *sep = lual_checkstring(l, 2); const char *e; int i = 1; lua_newtable(l); while ((e = strchr(s, *sep)) != null) { lua_pushlstring(l, s, e-s); lua_rawseti(l, -2, i ++); s = e + 1; } lua_pushstring(l, s); lua_rawseti(l, -2, i); return 1;}int l_map(lua_state *l){ int i, n; lual_checktype(l, 1, lua_ttable); lual_checktype(l, 2, lua_tfunction); n = lua_objlen(l, 1); for (i = 1; i test.lua
bule = {r = 0, g = 0, b = 1}table = {[r] = 10, [g] = 23, [b] = 33}function f(x, y) return x + yend
编译:gcc test.c -i/usr/local/include/luajit-2.0 -llua-5.1 -lm
以上就介绍了lua与c语言互相调用,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。