Tremulous + Lua

Just going to leave this here

Lua script

--[[
 _____                         _                       _
|_   _| __ ___ _ __ ___  _   _| | ___  _   _ ___      | |   _   _  __ _
  | || '__/ _ \ '_ ` _ \| | | | |/ _ \| | | / __|_____| |  | | | |/ _` |
  | || | |  __/ | | | | | |_| | | (_) | |_| \__ \_____| |__| |_| | (_| |
  |_||_|  \___|_| |_| |_|\__,_|_|\___/ \__,_|___/     |_____\__,_|\__,_|
  Victor Roemer [WTFBBQHAX]
  Nov. 03, 2016 10:53:27AM EST
  A sample Restful JSON Client API.
  This sample demonstrates how to comunicate with an HTTP JSON 3rdparty
  API in Lua script.
  APIs demonstrated:
    * HTTP RestClient
    * JSON
--]]

-- GitHub API URL
url='https://api.github.com/repos/wtfbbqhax/tremulous/releases'

-- HTTP Get request- retrieve the raw JSON response
txt = http.get(url)
assert(txt.code == 200)

-- Decode raw JSON response into a Lua table
releases = rapidjson.decode(txt.body)

-- GitHub returned an array of releases- The "most_recent" is item 1
-- NOTE: Lua array indexing starts at `1` not `0`!!
most_recent = releases[1]

-- FIXME: Remove hardcoded tag_name in this test
assert(most_recent.tag_name == "Oct-22-2016")

for i,asset in ipairs(most_recent.assets) do
    print(asset.browser_download_url)
end

Screenshot

5 Likes

Is that a new mod for Tremulous? :confused:

I am no programmer, but based on what I can read from BlowFish’s OP:

This sample demonstrates how to comunicate with an HTTP JSON 3rdparty
API in Lua script.

It appears to me that the LUA programming language is being demonstrated within the Tremulous (1.3?) client itself. I assume this is a mostly developer thing to be excited about, as people can eventually make COOL SHIT™ using LUA.

Though I think if we ask @blowFish politely, he might give us a proper explanation. :slight_smile:

Lua runtime is embedded in both Tremulous client and server executables. Largely this implementation allows for in-console scripting and loading scripts from disk. There is a growing API provided to Lua, 2 of these are HTTP and JSON; These make interacting with 3rd party API’s trivial.

A short list of HTTP/JSON api’s available:

  • Slack
  • Discord
  • Spotify
  • YouTube
  • GitHub
  • Twitch.tv

    basically everything

You could write a Lua script for your server to log in game chat to a slack channel.

Control Spotify in your client; or publish radio stations from a server.

3 Likes

Another thing you can do is write/run Lua scripts from within your client’s console, for hopefully non-malicious uses :wink: .

Lua support is already available on @blowFish 's public repo, and will be included in GrangerHub’s pre-release client (and subsequently in the 1.3 initial release).

Some other things that potentially can be done with Lua integration with Trem (although these following things are not planned for the 1.3 initial release) is Lua scripting for maps, Lua scripting supplements/complements to the game logic, or even completely replacing some or all of the kinds of QVMs with Lua scripts (the ioquake3 engine has 3 types of QVMs: game QVM used by the server, and the cgame & ui QVMs used by the client).

2 Likes

:point_up_2:

We will probably have support for Lua defined game logic by 1.3 release. We just won’t be using it in the 1.3 release.

3 Likes

spring makes heavy use of lua in a interesting way.
Im really looking foward to scripting support in trem, this will be awesome to say the least.

4 Likes