File: cstub.c

package info (click to toggle)
lua-ljsyscall 0.12-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,732 kB
  • sloc: ansic: 434; sh: 59; makefile: 3
file content (30 lines) | stat: -rw-r--r-- 570 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* simple example to show a C file linked with ljsyscall */

#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

#include <stdlib.h>
#include <stdio.h>

void lerror(lua_State *L, char *msg) {
  fprintf(stderr, "\nFATAL ERROR:\n  %s: %s\n\n", msg, lua_tostring(L, -1));
  lua_close(L);
  exit(1);
}

int main(void) {
  lua_State *L;

  L = luaL_newstate();
  luaL_openlibs(L);

  if (luaL_loadstring(L, "require \"test.test\""))
	lerror(L, "luaL_loadstring() failed");
  if (lua_pcall(L, 0, 0, 0))
	lerror(L, "lua_pcall() failed");

  lua_close(L);

  return 0;
}