panorama
Run JavaScript in Panorama panels with panorama.loadstring and read Panorama globals from Lua.
Panorama is the game's JavaScript UI. Calls must run on the main game thread; calls from other threads return nil.
A panel argument is a panel ID, searched first in the HUD while in game, then in the main menu. Its default is "CSGOMainMenu".
panorama.loadstring
panorama.loadstring(js, panel?)Compiles js as a function body. Call the returned object to execute it; use JavaScript return to produce a result.
Returns: a callable panorama.object, or nil, err when the body does not compile (nil alone off Panorama's main thread or when the panel is missing). Compilation errors are also printed in the Panorama console. A body V8 cannot take returns nil, "the source is too long for V8".
Calling the returned object answers the function's result, or nil, err when the JavaScript throws; the exception still goes to the Panorama console. When the engine stops the script without a result or an exception, err is the engine stopped the script before it returned or threw (see the Panorama console). Otherwise err is the message, the position in js and V8's stack:
Error: boom (line 2, column 9)
Error: boom
at cs2hk-js-14:3:9Lines count from the first line of js. A thrown value without a usable stack has no position. Only functions loadstring returned report errors; any other JavaScript function called from Lua answers a bare nil when it throws.
local get_map, compile_error = panorama.loadstring('return GameStateAPI.GetMapBSPName();')
if get_map then
local map, err = get_map()
if err then
print('panorama: ' .. err)
else
print(map)
end
elseif compile_error then
print('panorama: ' .. compile_error)
endEach call of a loaded function is a fresh function call: a top-level var or function in js is local to that call. Keep state across calls on the panel context's global object:
local count = assert(panorama.loadstring('globalThis.nixware_count = (globalThis.nixware_count || 0) + 1; return globalThis.nixware_count;'))
print(count(), count()) -- 1 2Panorama lookup
panorama.CSGOHud
panorama.GameStateAPIIf the name identifies a panel, returns its JavaScript global object. Otherwise reads the property from the main menu's global object and converts it to Lua.
Returns: a panorama.object, a converted Lua value, or nil.
