/* creates a new instance of a Camera */ int LuaCamera::create(lua_State* L) { Camera *c; // checks for args if(lua_type(L, 1) == LUA_TUSERDATA) { Point *loc = LuaPoint::checkInstance(L, 1); if(lua_type(L, 2) == LUA_TUSERDATA) { Vector *view = LuaVector::checkInstance(L, 2); if(lua_type(L, 3) == LUA_TUSERDATA) { Vector *up = LuaVector::checkInstance(L, 3); c = new Camera(*loc, *view, *up); } else { c = new Camera(*loc, *view); } } else { c = new Camera(*loc); } } else { c = new Camera; } lua_boxpointer(L, c); luaL_getmetatable(L, className); lua_setmetatable(L, -2); return 1; }
static M_APM Bnew(lua_State *L) { M_APM x=m_apm_init(); lua_boxpointer(L,x); luaL_setmetatable(L,MYTYPE); return x; }
/* * Returns: reg_udata */ static int reg_new (lua_State *L) { lua_boxpointer(L, NULL); luaL_getmetatable(L, WREG_TYPENAME); lua_setmetatable(L, -2); return 1; }
/* creates a new instance of a Patch */ int LuaPatch::create(lua_State* L) { Patch *p = new Patch; lua_boxpointer(L, p); luaL_getmetatable(L, className); lua_setmetatable(L, -2); return 1; }
int ml_socache_lookup(lua_State*L) { const request_rec* r = CHECK_REQUEST_OBJECT(1); server_rec *s = r->server; apr_pool_t *pool = s->process->pool; //store provider in pool const char *provider_id = luaL_checkstring(L, 2); apr_time_t timeout = luaL_optint(L, 3, 30 * 60); const char *provider_name = luaL_optstring(L, 4, AP_SOCACHE_DEFAULT_PROVIDER); const char *provider_arg = luaL_optstring(L, 5, NULL); ml_socache *c = NULL; apr_status_t status = APR_SUCCESS; char socache_key[128]; struct ap_socache_hints hints = {0}; hints.avg_id_len = 64; hints.avg_obj_size = 1024; hints.expiry_interval = timeout; apr_snprintf(socache_key, 128, "%s_%s_%s", provider_id, provider_name, AP_SOCACHE_PROVIDER_GROUP); status = apr_pool_userdata_get((void**)&c, socache_key, pool); if ( status == APR_SUCCESS ) { if (c == NULL) { const char* err; c = lua_newuserdata(L, sizeof(ml_socache)); c->_provider = ap_lookup_provider(AP_SOCACHE_PROVIDER_GROUP, provider_name, AP_SOCACHE_PROVIDER_VERSION); err = c->_provider->create(&c->_instance, provider_arg, pool, pool); if (err) { luaL_error(L, err); } c->_provider->init(c->_instance, provider_id, &hints, s, pool); c->_server = s; c->_timeout = timeout * APR_USEC_PER_SEC; c->_maxdatalen = 1024; apr_pool_userdata_set(c, socache_key, apr_pool_cleanup_null, pool); } c->_pool = r->pool; lua_boxpointer(L, c); luaL_getmetatable(L, "mod_luaex.socache"); lua_setmetatable(L, -2); } else { char err[APR_PATH_MAX]; apr_strerror(status, err, APR_PATH_MAX); luaL_error(L, err); } return 1; }
/* gets the up direction of the Camera */ int LuaCamera::up(lua_State* L) { Camera *c = checkInstance(L, 1); Vector *v = new Vector; *v = c->up(); lua_boxpointer(L, v); luaL_getmetatable(L, "Vector"); lua_setmetatable(L, -2); return 1; }
/* gets the location of the Camera */ int LuaCamera::location(lua_State* L) { Camera *c = checkInstance(L, 1); Point *p = new Point; *p = c->location(); lua_boxpointer(L, p); luaL_getmetatable(L, "Point"); lua_setmetatable(L, -2); return 1; }
int luaCompat_newTypedObject(lua_State* L, void* object) { /* lua5 */ LUASTACK_SET(L); luaL_checktype(L, -1, LUA_TTABLE); lua_boxpointer(L, object); lua_insert(L, -2); lua_setmetatable(L, -2); LUASTACK_CLEAN(L, 0); return 1; }
int LuaFosterWaterVolume::point(lua_State* L) { FosterWaterVolume *wv = checkInstance(L, 1); double i = luaL_checknumber(L, 2); double j = luaL_checknumber(L, 3); double k = luaL_checknumber(L, 4); Point *p = new Point; *p = wv->point(static_cast<unsigned>(i), static_cast<unsigned>(j), static_cast<unsigned>(k)); lua_boxpointer(L, p); luaL_getmetatable(L, "Point"); lua_setmetatable(L, -2); return 1; }
int LuaFosterWaterVolume::velocity(lua_State* L) { FosterWaterVolume *wv = checkInstance(L, 1); double i = luaL_checknumber(L, 2); double j = luaL_checknumber(L, 3); double k = luaL_checknumber(L, 4); Vector *v = new Vector; *v = wv->velocity(static_cast<unsigned>(i), static_cast<unsigned>(j), static_cast<unsigned>(k)); lua_boxpointer(L, v); luaL_getmetatable(L, "Vector"); lua_setmetatable(L, -2); return 1; }
bool _pushuser( lua_State* L, void *ctx, const char * clsName ) { lua_newtable(L); lua_pushnumber( L, 1 ); // new object, new table. lua_boxpointer( L, ctx ); // box 'this' // Get our deleter metatable lua_pushstring(L,"e6_objectmeta"); lua_gettable(L,LUA_REGISTRYINDEX); lua_setmetatable(L,-2); // set the pointer lua_rawset(L, -3); // now set the object-metatable : lua_pushstring( L, clsName ); lua_gettable( L, LUA_REGISTRYINDEX ); lua_setmetatable( L, -2 ); lua_settop(L, 1 ); return 1; }
static int container_new(lua_State *L) { struct lxc_container *c; const char *name = luaL_checkstring(L, 1); const char *configpath = NULL; int argc = lua_gettop(L); if (argc > 1) configpath = luaL_checkstring(L, 2); c = lxc_container_new(name, configpath); if (c) { lua_boxpointer(L, c); luaL_getmetatable(L, CONTAINER_TYPENAME); lua_setmetatable(L, -2); } else { lua_pushnil(L); } return 1; }
int LuaFosterWaterVolume::create(lua_State* L) { Point *p = LuaPoint::checkInstance(L, 1); double size_x = luaL_checknumber(L, 2); double size_y = luaL_checknumber(L, 3); double size_z = luaL_checknumber(L, 4); double step_x = luaL_checknumber(L, 5); double step_y = luaL_checknumber(L, 6); double step_z = luaL_checknumber(L, 7); FosterWaterVolume *wv = new FosterWaterVolume(*p, static_cast<unsigned>(size_x), static_cast<unsigned>(size_y), static_cast<unsigned>(size_z), step_x, step_y, step_z); lua_boxpointer(L, wv); luaL_getmetatable(L, _class_name); lua_setmetatable(L, -2); return 1; }
/* pushs one of the World's views, given its index, onto the Lua stack */ int LuaWorld::view(lua_State *L) { World *world = World::instance(); double index = luaL_checknumber(L, 1); if(index < 0) { luaL_argerror(L, 1, "view index must be non-negative"); } WorldView *wv = world->view(static_cast<unsigned>(index)); /* * If this view is a 3D view I can't delete it when it gets out of * the Lua scope, for it belongs to the toolkit. I then add a * reference to it in the Lua registry. Must think of a better * way of sync this two worlds later. */ if(wv) { lua_pushlightuserdata(L, wv); lua_gettable(L, LUA_REGISTRYINDEX); if(!lua_isuserdata(L, -1) || lua_islightuserdata(L, -1)) { lua_pop(L, 1); lua_boxpointer(L, wv); luaL_getmetatable(L, "WorldView"); lua_setmetatable(L, -2); if(dynamic_cast<WorldView3D*>(wv)) { lua_pushlightuserdata(L, wv); lua_pushvalue(L, -2); lua_settable(L, LUA_REGISTRYINDEX); } } } else { lua_pushnil(L); } return 1; }
int LuaNoiseVolumeRenderer::create(lua_State* L) { void *ud; Orbis::Drawable::WaterVolume *wv; NoiseVolumeRenderer *noise = 0; luaL_checktype(L, 1, LUA_TUSERDATA); ud = luaL_checkudata(L, 1, "FosterWaterVolume"); if(ud) { wv = *(static_cast<Orbis::Drawable::FosterWaterVolume**>(ud)); } else { ud = luaL_checkudata(L, 1, "StamWaterVolume"); if(ud) { wv = *(static_cast<Orbis::Drawable::StamWaterVolume**>(ud)); } else { wv = 0; luaL_typerror(L, 1, "WaterVolume"); } } if(lua_gettop(L) == 1) { noise = new NoiseVolumeRenderer(wv); } else if(lua_gettop(L) == 2) { double t = luaL_checknumber(L, 2); noise = new NoiseVolumeRenderer(wv, t); } else { luaL_error(L, "wrong number of arguments to IsoSurfaceRenderer"); } noise->ref(); lua_boxpointer(L, noise); luaL_getmetatable(L, _class_name); lua_setmetatable(L, -2); return 1; }
void ap_lua_push_apr_table(lua_State *L, apr_table_t *t) { lua_boxpointer(L, t); luaL_getmetatable(L, "Apr.Table"); lua_setmetatable(L, -2); }
void luaL_pushrequest(lua_State* L, request_t* r) { lua_boxpointer(L, r); luaL_getmetatable(L, "LuaFCGId.Request"); lua_setmetatable(L, -2); }