void BindInput() { Sqrat::Class<CInput, Sqrat::NoConstructor> def; def.Func("KeyUp", &CInput::KeyUp); def.Func("KeyPressed", &CInput::KeyPressed); def.Func("KeyHeld", &CInput::KeyHeld); def.Func("KeyReleased", &CInput::KeyReleased); Sqrat::RootTable().Bind("InputSystem", def); //Sqrat::ConstTable().Const("KEY_LEFT", KEY_LEFT); MAKE_KEY( KEY_LEFT ); MAKE_KEY( KEY_RIGHT ); MAKE_KEY( KEY_UP ); MAKE_KEY( KEY_DOWN ); MAKE_KEY( KEY_Q ); MAKE_KEY( KEY_W ); MAKE_KEY( KEY_PAGEUP ); MAKE_KEY( KEY_PAGEDOWN ); MAKE_KEY( KEY_HOME ); // Push the singleton to squirrel sq_pushroottable( Sqrat::DefaultVM::Get() ); sq_pushstring( Sqrat::DefaultVM::Get(), "InputSystem", -1 ); sq_get( Sqrat::DefaultVM::Get(), -2 ); sq_pushstring( Sqrat::DefaultVM::Get(), "Input", -1 ); sq_createinstance( Sqrat::DefaultVM::Get(), -2 ); sq_setinstanceup( Sqrat::DefaultVM::Get(), -1, (SQUserPointer)Input() ); sq_newslot( Sqrat::DefaultVM::Get(), -4, SQFalse ); sq_pop( Sqrat::DefaultVM::Get(), 2 ); }
void BindPongPlayer() { Sqrat::Class<CPongPlayer> def; def.Func("Init", &CPongPlayer::Init); Sqrat::RootTable().Bind("PongPlayer", def); }
void BindClass_CSprite() { Sqrat::Class<CSprite> def; def.Func("LoadTexture", &CSprite::LoadTexture); def.Func("Spawn", &CSprite::Spawn); def.Func("Think", &CSprite::Think); def.Func("Render", &CSprite::Render); def.Func("SetPos", &CSprite::SetPos ); def.Var("x", &CSprite::m_flPosX ); def.Var("y", &CSprite::m_flPosY ); def.Var("rot", &CSprite::m_flRotation ); def.Var("scale", &CSprite::m_flScale ); Sqrat::RootTable().Bind("Sprite", def); }
bool SqMod::construct(CtxMod* pctx) { _pctx = pctx; _header_sent=false; if(_penv) { _penv->acquire(); Sqrat::Class<SqMod> module; module.Func(_SC("write"), &SqMod::swrite); Sqrat::RootTable().SetInstance(_SC("_this"), this); // // _context // Sqrat::Table context; //Sqrat::Class<CtxMod> context; context.SetValue(_SC("urldoc"), pctx->_url_doc) .SetValue(_SC("urldir"), pctx->_url_path) .SetValue(_SC("home"), pctx->_dir_home) .SetValue(_SC("index"), pctx->_doc_index) .SetValue(_SC("ip"), pctx->_cli_ip); Sqrat::RootTable().Bind(_SC("_context"), context); // // _REQ table with _ARGS, GET, COOKIE and so on // Sqrat::Table headers; const KeyValx* ps = _pctx->_hdrs; while((ps)->key) { if(ps->val && *ps->val) { headers.SetValue(_SC(ps->key), _SC(ps->val)); } ++ps; } Sqrat::RootTable().Bind(_SC("_request"), headers); Sqrat::Table ckooks; const KeyValx* psc = _pctx->_cookies; while((psc)->key) { if(psc->val && *psc->val) { ckooks.SetValue(_SC(psc->key), _SC(psc->val)); } ++psc; } Sqrat::RootTable().Bind(_SC("_cookies"), ckooks); Sqrat::Table get; const KeyValx* psv = _pctx->_get; while((psv)->key) { if(psv->val && *psv->val) { get.SetValue(_SC(psv->key), _SC(psv->val)); } ++psv; } Sqrat::RootTable().Bind(_SC("_get"), get); //Sqrat::RootTable().SetInstance(_SC("_ctx"), pctx); Sqrat::Table post; if(pctx->_tempfile) { // parse the post /* Content-Type: application/x-www-form-urlencoded Content-Length: 53 realname=ssssssss&email=ddddddddddd&comments=wwwwwwww */ const char* astype = _getHdr("CONTENT-TYPE")->val; int64_t len = atoll(_getHdr("CONTENT-LENGTH")->val); if(!str_cmp(astype,"application/x-www-form-urlencoded") && len < 16384) { char* buff = new char[len + 1]; if(buff) { int bytes = fread(buff, 1, len, pctx->_tempfile); char* pwalk = buff; assert(bytes == len); buff[bytes] = 0; do { const char* key = str_up2chr(&pwalk, '='); const char* val = str_up2chr(&pwalk, '&'); if(!valid_ptr(key) || !valid_ptr(val)) break; post.SetValue(_SC(key), _SC(val)); } while(1); delete []buff; } } } Sqrat::RootTable().Bind(_SC("_post"), post); return true; } return false; }