Beispiel #1
0
/*
 * Arguments: dest. dib_udata, source dib_udata,
 *	left (number), top (number), alpha (number)
 * Returns: [dest. dib_udata]
 */
static int
dib_paste (lua_State *L)
{
  FIBITMAP *dst_dib = lua_unboxpointer(L, 1, DIB_TYPENAME);
  FIBITMAP *src_dib = lua_unboxpointer(L, 2, DIB_TYPENAME);
  const int left = lua_tointeger(L, 3);
  const int top = lua_tointeger(L, 4);
  const int alpha = lua_tointeger(L, 5);

  return dib_checkerror(L,
   FreeImage_Paste(dst_dib, src_dib, left, top, alpha) ? dst_dib : NULL);
}
Beispiel #2
0
/*
 * Arguments: ecb_udata, name (string), value (string | number)
 */
static int
ecb_header (lua_State *L)
{
  LPEXTENSION_CONTROL_BLOCK ecb = lua_unboxpointer(L, 1, ECB_TYPENAME);
  const int headers = (ecb->dwHttpStatusCode & ~ECB_STATUS_MASK);
  const char *name = luaL_checkstring(L, 2);

  if (headers == ECB_STATUS_HEADERS)
    luaL_error(L, "Headers already sent");

  if (!strcmp(name, "Status")) {
    ecb->dwHttpStatusCode &= ~ECB_STATUS_MASK;
    ecb->dwHttpStatusCode |= lua_tointeger(L, 3) & ECB_STATUS_MASK;
    return 0;
  }
  luaL_checktype(L, 3, LUA_TSTRING);

  lua_pushliteral(L, ": ");
  lua_insert(L, 3);
  lua_pushliteral(L, "\r\n");

  if (headers) {
    lua_rawgetp(L, LUA_REGISTRYINDEX, ecb);
  } else {
    lua_pushliteral(L, "");
  }

  lua_concat(L, 5);
  lua_rawsetp(L, LUA_REGISTRYINDEX, ecb);

  ecb->dwHttpStatusCode |= ECB_STATUS_HEADERS | ECB_STATUS_HEADERS_SEND;
  return 0;
}
Beispiel #3
0
static int container_defined(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);

    lua_pushboolean(L, !!c->is_defined(c));
    return 1;
}
apr_table_t *ap_lua_check_apr_table(lua_State *L, int index)
{
    apr_table_t *t;
    luaL_checkudata(L, index, "Apr.Table");
    t = lua_unboxpointer(L, index);
    return t;
}
Beispiel #5
0
static int container_init_pid(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);

    lua_pushinteger(L, c->init_pid(c));
    return 1;
}
Beispiel #6
0
/*
 * Arguments: ecb_udata, variable_name (string)
 * Returns: value (string | number)
 */
static int
ecb_getvar (lua_State *L)
{
  LPEXTENSION_CONTROL_BLOCK ecb = lua_unboxpointer(L, 1, ECB_TYPENAME);
  const char *name = luaL_checkstring(L, 2);
  const char *val = NULL;

  if (!strcmp(name, "REQUEST_METHOD"))
    val = ecb->lpszMethod;
  else if (!strcmp(name, "QUERY_STRING"))
    val = ecb->lpszQueryString;
  else if (!strcmp(name, "PATH_INFO"))
    val = ecb->lpszPathInfo;
  else if (!strcmp(name, "PATH_TRANSLATED"))
    val = ecb->lpszPathTranslated;
  else if (!strcmp(name, "CONTENT_TYPE"))
    val = ecb->lpszContentType;
  else if (!strcmp(name, "CONTENT_LENGTH")) {
    lua_pushinteger(L, ecb->cbTotalBytes);
    return 1;
  }
  if (val) {
    lua_pushstring(L, val);
    return 1;
  } else {
    char buf[SYS_BUFSIZE];
    DWORD len = sizeof(buf);

    if (ecb->GetServerVariable(ecb->ConnID, (char *) name, buf, &len)) {
      lua_pushlstring(L, buf, len - 1);
      return 1;
    }
  }
  return sys_seterror(L, 0);
}
Beispiel #7
0
static request_rec *ap_lua_check_request_rec(lua_State *L, int index)
{
    request_rec *r;
    luaL_checkudata(L, index, "Apache2.Request");
    r = lua_unboxpointer(L, index);
    return r;
}
Beispiel #8
0
/* container state */
static int container_start(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
    int argc = lua_gettop(L);
    char **argv = NULL;
    int i,j;
    int useinit = 0;

    if (argc > 1) {
	argv = alloca((argc+1) * sizeof(char *));
	for (i = 0, j = 0; i < argc-1; i++) {
	    const char *arg = luaL_checkstring(L, i+2);

	    if (!strcmp(arg, "useinit"))
		useinit = 1;
	    else
		argv[j++] = strdupa(arg);
	}
	argv[j] = NULL;
    }

    c->want_daemonize(c, true);
    lua_pushboolean(L, !!c->start(c, useinit, argv));
    return 1;
}
Beispiel #9
0
SAMPLE *Item::obdata_get_sound_sample(uint32 item_index, const char *property_name, int sample_index)
{
    int stack_top = lua_gettop(L);
    // Enter 'ItemsTable' table
    lua_pushstring(L, "ItemsTable");
    lua_gettable(L, LUA_GLOBALSINDEX);
    ASSERT(lua_istable(L, -1)); 
    // Enter [item_index] table
    lua_pushnumber(L, item_index);
    lua_gettable(L, -2);
    ASSERT(lua_istable(L, -1));
    // Get property value
    lua_pushstring(L, property_name);
    lua_gettable(L, -2);
    SAMPLE *result = NULL;
    if (lua_istable(L, -1)) {
        lua_pushnumber(L, sample_index);
        lua_gettable(L, -2);
    }
    if (lua_isuserdata(L, -1)) {
        ASSERT(lpcd_isuserdatatype(L, -1, "SAMPLE"));
        result = (SAMPLE *)lua_unboxpointer(L, -1);
    }
    lua_settop(L, stack_top);
    return result;
}
Beispiel #10
0
/*
 * Arguments: dest. dib_udata, foreground dib_udata,
 *	[use_file_background (boolean), app_background_color (Color),
 *	background dib_udata]
 * Returns: [dest. dib_udata]
 */
static int
dib_composite (lua_State *L)
{
  FIBITMAP **dibp = checkudata(L, 1, DIB_TYPENAME);
  FIBITMAP *fg_dib = lua_unboxpointer(L, 2, DIB_TYPENAME);
  const BOOL use_file_bkg = lua_toboolean(L, 3);
  RGBQUAD app_bkcolor;
  const int i = lua_isnoneornil(L, 4)
   ? 0 : (lfi_tocolor(L, 4, &app_bkcolor), 1);
  FIBITMAP *bg_dib = lua_isuserdata(L, 4 + i)
   ? lua_unboxpointer(L, 4 + i, DIB_TYPENAME) : NULL;

  *dibp = FreeImage_Composite(fg_dib, use_file_bkg,
   i ? &app_bkcolor : NULL, bg_dib);
  return dib_checkerror(L, *dibp);
}
Beispiel #11
0
static int container_get_keys(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
    const char *key = NULL;
    int len;
    char *value;
    int arg_cnt = lua_gettop(L);

    if (arg_cnt > 1)
	key = luaL_checkstring(L, 2);

    len = c->get_keys(c, key, NULL, 0);
    if (len <= 0)
	goto not_found;

    value = alloca(sizeof(char)*len + 1);
    if (c->get_keys(c, key, value, len + 1) != len)
	goto not_found;

    lua_pushstring(L, value);
    return 1;

not_found:
    lua_pushnil(L);
    return 1;
}
Beispiel #12
0
static int container_state(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);

    lua_pushstring(L, c->state(c));
    return 1;
}
Beispiel #13
0
static cmd_parms *check_cmd_parms(lua_State *L, int index)
{
    cmd_parms *cmd;
    luaL_checkudata(L, index, "Apache2.CommandParameters");
    cmd = (cmd_parms *) lua_unboxpointer(L, index);
    return cmd;
}
Beispiel #14
0
static ap_lua_dir_cfg *check_dir_config(lua_State *L, int index)
{
    ap_lua_dir_cfg *cfg;
    luaL_checkudata(L, index, "Apache2.DirConfig");
    cfg = (ap_lua_dir_cfg *) lua_unboxpointer(L, index);
    return cfg;
}
Beispiel #15
0
static int container_shutdown(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
    int timeout = luaL_checkinteger(L, 2);

    lua_pushboolean(L, !!c->shutdown(c, timeout));
    return 1;
}
Beispiel #16
0
/*
 * Arguments: pipe_udata
 * Returns: string
 */
static int
pipe_tostring (lua_State *L)
{
    struct pipe *pp = lua_unboxpointer(L, 1, PIPE_TYPENAME);

    lua_pushfstring(L, PIPE_TYPENAME " (%p)", pp);
    return 1;
}
Beispiel #17
0
/* collects the memory of a Camera */
int LuaCamera::collect(lua_State* L)
{
	Camera *c = (Camera*) lua_unboxpointer(L, 1);

	delete c;

	return 0;
}
int LuaNoiseVolumeRenderer::collect(lua_State* L)
{
	NoiseVolumeRenderer *noise = (NoiseVolumeRenderer*) lua_unboxpointer(L, 1);

	noise->unref();

	return 0;
}
Beispiel #19
0
/* collects the memory of a Patch */
int LuaPatch::collect(lua_State* L)
{
    Patch *p = (Patch*) lua_unboxpointer(L, 1);

    delete p;

    return 0;
}
Beispiel #20
0
/*
 * Arguments: ecb_udata
 * Returns: data (string)
 */
static int
ecb_data (lua_State *L)
{
  LPEXTENSION_CONTROL_BLOCK ecb = lua_unboxpointer(L, 1, ECB_TYPENAME);

  lua_pushlstring(L, (const char *) ecb->lpbData, ecb->cbAvailable);
  return 1;
}
Beispiel #21
0
int LuaFosterWaterVolume::collect(lua_State* L)
{
	FosterWaterVolume *wv = static_cast<FosterWaterVolume*>(lua_unboxpointer(L, 1));

	delete wv;

	return 0;
}
Beispiel #22
0
static int container_clear_config_item(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
    const char *key = luaL_checkstring(L, 2);

    lua_pushboolean(L, !!c->clear_config_item(c, key));
    return 1;
}
Beispiel #23
0
/*
 * Arguments: ecb_udata
 */
static int
ecb_req_pending (lua_State *L)
{
  LPEXTENSION_CONTROL_BLOCK ecb = lua_unboxpointer(L, 1, ECB_TYPENAME);

  ecb->dwHttpStatusCode |= ECB_STATUS_PENDING;
  return 0;
}
Beispiel #24
0
static int container_gc(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);

    /* XXX what to do if this fails? */
    lxc_container_put(c);
    return 0;
}
Beispiel #25
0
static int container_set_config_path(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
    const char *config_path = luaL_checkstring(L, 2);

    lua_pushboolean(L, !!c->set_config_path(c, config_path));
    return 1;
}
TOLUA_API void* tolua_tofieldusertype (lua_State* L, int lo, int index, void* def)
{
 void* v;
 lua_pushnumber(L,index);
 lua_gettable(L,lo);
 v = lua_isnil(L,-1) ? def : lua_unboxpointer(L,-1);
 lua_pop(L,1);
 return v;
}
Beispiel #27
0
static int container_set_cgroup_item(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
    const char *key = luaL_checkstring(L, 2);
    const char *value = luaL_checkstring(L, 3);

    lua_pushboolean(L, !!c->set_cgroup_item(c, key, value));
    return 1;
}
Beispiel #28
0
static int container_get_config_path(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
    const char *config_path;

    config_path = c->get_config_path(c);
    lua_pushstring(L, config_path);
    return 1;
}
Beispiel #29
0
static int container_wait(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
    const char *state = luaL_checkstring(L, 2);
    int timeout = luaL_checkinteger(L, 3);

    lua_pushboolean(L, !!c->wait(c, state, timeout));
    return 1;
}
Beispiel #30
0
static int container_config_file_name(lua_State *L)
{
    struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
    char *config_file_name;

    config_file_name = c->config_file_name(c);
    lua_pushstring(L, config_file_name);
    free(config_file_name);
    return 1;
}