Created
August 23, 2018 03:31
-
-
Save adam000/cd459f06145f832ea77acf2b9b9b312a to your computer and use it in GitHub Desktop.
Some of this is taken from the PiL book example on doing this in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #cgo pkg-config: lua | |
/* | |
#include "lua.h" | |
#include "lauxlib.h" | |
#include "lualib.h" | |
#include <string.h> | |
#include <stdio.h> | |
void process_line(char* buff, lua_State* L) { | |
luaL_openlibs(L); | |
int error = luaL_loadbuffer(L, buff, strlen(buff), "line") || lua_pcall(L, 0, 0, 0); | |
if (error) { | |
fprintf(stderr, "%s\n", lua_tostring(L, -1)); | |
lua_pop(L, 1); | |
} | |
} | |
void read_forever() { | |
char buff[256]; | |
lua_State *L = luaL_newstate(); | |
setbuf(stdout, NULL); | |
printf("> "); | |
while (fgets(buff, sizeof(buff), stdin) != NULL) { | |
process_line(&buff[0], L); | |
printf("> "); | |
} | |
lua_close(L); | |
} | |
*/ | |
import "C" | |
import "log" | |
func main() { | |
C.read_forever() | |
log.Println("Done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment