Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
// This file: // http://anggtwu.net/LISP/2025-lua-runstring-0.c.html // http://anggtwu.net/LISP/2025-lua-runstring-0.c // (find-angg "LISP/2025-lua-runstring-0.c") // See: http://anggtwu.net/2025-calling-lua-from-common-lisp.html // Author: Eduardo Ochs <eduardoochs@gmail.com> #include <lua.h> #include <lauxlib.h> #include <lualib.h> #include <stdio.h> static lua_State *L = NULL; const char *lua_runstring(char *str) { const char *result; if (!L) { L = luaL_newstate(); luaL_openlibs(L); } lua_getglobal (L, "load"); lua_pushstring (L, str); lua_call (L, 1, 1); lua_call (L, 0, 1); result = lua_tostring(L, -1); lua_pop(L, 1); return result; } #ifdef MAIN int main(int argc, const char ** argv) { printf("%s\n", lua_runstring("return 'a'..'b'")); return 0; } #endif /* * (eepitch-shell) * (eepitch-kill) * (eepitch-shell) LUA_INCLUDE_DIR=/usr/include/lua5.3 LUA_LIB=lua5.3 STEM=2025-lua-runstring-0 gcc -g -shared -I${LUA_INCLUDE_DIR} -o ${STEM}.so ${STEM}.c -l${LUA_LIB} gcc -g -DMAIN -I${LUA_INCLUDE_DIR} -o ${STEM} ${STEM}.c -l${LUA_LIB} ls -lAF ${STEM}* ./${STEM} * (eepitch-sly) * (eepitch-kill) * (eepitch-sly) (load #P"~/quicklisp/setup.lisp") (ql:quickload :cffi) (cffi:load-foreign-library "./2025-lua-runstring-0.so") (defun lua-runstring (str) (cffi:foreign-funcall "lua_runstring" :string str :string)) (lua-runstring "return 'ab'..'cd'") */