Example #1
0
void *
lua_create_instance(void)
{
	luaServer_t * p;
	lua_State * L;

	p = (luaServer_t *)calloc(1, sizeof(luaServer_t));
	if (p == NULL)
		return NULL;

	L = luaL_newstate();
	if ( L == NULL ) {
		free(p);
		return NULL;
	}

	p->client_socket	= -1;
	p->server_socket	= -1;
	p->in				= NULL;
	p->out				= NULL;
	p->err				= NULL;

	luaL_setprivate(L, p);

	// Make sure we display the copyright string for Lua.
	lua_writestring(L, LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
	lua_writeline(L);

	lua_newlibs_init(L);

    return L;
}
Example #2
0
static int luaB_print (lua_State *L) {
  int n = lua_gettop(L);  /* number of arguments */
  int i;
  lua_getglobal(L, "tostring");
  for (i=1; i<=n; i++) {
    const char *s;
    size_t l;
    lua_pushvalue(L, -1);  /* function to be called */
    lua_pushvalue(L, i);   /* value to print */
    lua_call(L, 1, 1);
    s = lua_tolstring(L, -1, &l);  /* get result */
    if (s == NULL)
      return luaL_error(L, "'tostring' must return a string to 'print'");
    if (i>1) lua_writestring("\t", 1);
    lua_writestring(s, l);
    lua_pop(L, 1);  /* pop result */
  }
  lua_writeline();
  return 0;
}
Example #3
0
static void print_version (void) {
  lua_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
  lua_writeline();
}