diff options
author | nat-goodspeed <nat@lindenlab.com> | 2024-09-24 07:28:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 07:28:44 -0400 |
commit | 1175288a3c685310dbbf7fdd46d7deae0b0bf92d (patch) | |
tree | 84fd4d186169807c4da1c0c352d9be92f1e63227 /indra/newview/scripts/lua/require/login.lua | |
parent | 0ee1106faccf90c883d8b9ffc522a341659742ed (diff) | |
parent | 9036e4582cec1893016bd692293ec1c0135f7112 (diff) |
Merge pull request #2534 from secondlife/release/luau-scripting
Add Lua scripting to develop, behind feature flag
Diffstat (limited to 'indra/newview/scripts/lua/require/login.lua')
-rw-r--r-- | indra/newview/scripts/lua/require/login.lua | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/indra/newview/scripts/lua/require/login.lua b/indra/newview/scripts/lua/require/login.lua new file mode 100644 index 0000000000..37c9093a21 --- /dev/null +++ b/indra/newview/scripts/lua/require/login.lua @@ -0,0 +1,42 @@ +local leap = require 'leap' +local startup = require 'startup' +local mapargs = require 'mapargs' + +local login = {} + +local function ensure_login_state(op) + -- no point trying to login until the viewer is ready + startup.wait('STATE_LOGIN_WAIT') + -- Once we've actually started login, LLPanelLogin is destroyed, and so is + -- its "LLPanelLogin" listener. At that point, + -- leap.request("LLPanelLogin", ...) will hang indefinitely because no one + -- is listening on that LLEventPump any more. Intercept that case and + -- produce a sensible error. + local state = startup.state() + if startup.before('STATE_LOGIN_WAIT', state) then + error(`Can't engage login operation {op} once we've reached state {state}`, 2) + end +end + +local function fullgrid(grid) + if string.find(grid, '.', 1, true) then + return grid + else + return `util.{grid}.secondlife.com` + end +end + +function login.login(...) + ensure_login_state('login') + local args = mapargs('username,grid,slurl', ...) + args.op = 'login' + args.grid = fullgrid(args.grid) + return leap.request('LLPanelLogin', args) +end + +function login.savedLogins(grid) + ensure_login_state('savedLogins') + return leap.request('LLPanelLogin', {op='savedLogins', grid=fullgrid(grid)})['logins'] +end + +return login |