|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
// This file:
// http://anggtwu.net/CLUA/foo.c.html
// http://anggtwu.net/CLUA/foo.c
// (find-angg "CLUA/foo.c")
// Skel: (find-luaso-links "~/CLUA/foo.c" "foo")
// Author: Eduardo Ochs <eduardoochs@gmail.com>
//
// (defun e () (interactive) (find-angg "CLUA/foo.c"))
// (find-books "__comp/__comp.el" "ierusalimschy")
// (find-books "__comp/__comp.el" "ierusalimschy" "247" "IV The C API")
#include "lauxlib.h"
#include <stdio.h>
static int my_foo(lua_State* L) {
lua_getglobal(L, "myprint");
// if (!lua_isnil(L, 0)) {
lua_pushstring(L, "bar");
lua_call(L, 1, 0);
// }
return 0;
// lua_pushnumber(L, 33);
// lua_pushnumber(L, 333);
// return 2;
}
static const struct luaL_reg foo_lib[] = {
{"foo", my_foo},
{NULL, NULL}
};
LUALIB_API int luaopen_foo(lua_State *L) {
lua_pushvalue(L, LUA_GLOBALSINDEX);
luaL_openlib(L, NULL, foo_lib, 0);
return 0;
}
/*
* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
gcc -g -Wall -shared -I/usr/include/lua5.1 -o foo.so foo.c
laf foo*
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
Path.prependtocpath "~/CLUA/?.so"
require "foo"
foo(42)
myprint = function (s) print("<"..s..">") end
foo(42)
*/