Attempt to call a non-function object

Hi all,

I’m using Nakama to add a matchmaking service for my multiplayer game created in Unity. I have been able to call my lua plugin which registers the match maker matched hook and calls a “match” plugin which implements the match handler functions as follows:

local nk = require("nakama")

local function matchmaker_matched(context, matchmaker_users)
  print("x-x-x-x-x--x-x-x-x-x-x-")

  return nk.match_create("match", {debug = true, expected_users = matchmaker_users})
end
nk.register_matchmaker_matched(matchmaker_matched)

In the match init function, I try to use Lua’s os.execute funtionality to spin up a new Unity backend server to handle a new match. However once the clients connect and the match is created, I get an error stating “attempt to call a non-function object.”

Googling this error, I don’t find one specific to nakama or even its usage in plugins. Is os.execute not supported in Nakama as yet? If so, what is the best way to call other programs that are on the same server?

local nk = require(“nakama”)

local M = {}

function M.match_init(context, setupstate)
print(“Match join attempt -------x-x-x-x-x–x-x----------|||||!!!|||||------------x-x-x-x------”)
os.execute(“echo hi”) – this produces an error
local gamestate = {
presences = {}
}
local tickrate = 1 – per sec
local label = “”
return gamestate, tickrate, label
end
…Rest of the match handler functions go here

Error message that is produced:

nakama         | {"level":"info","ts":"2020-05-15T03:46:25.004Z","msg":"New WebSocket session connected","uid":"fc0e9f1b-af2c-4242-b83c-796c7f8bbcb0","sid":"1906ff26-c9e4-4e04-8f86-6e14b4dcce11","format":0}
nakama         | {"level":"info","ts":"2020-05-15T03:46:25.197Z","msg":"New WebSocket session connected","uid":"dd24ac54-acbf-46a6-9e80-a30312af7802","sid":"5a88f210-aceb-4ad8-bc98-23e77edf90f1","format":0}
nakama         | x-x-x-x-x--x-x-x-x-x-x-
nakama         | Match join attempt -------x-x-x-x-x--x-x----------|||||!!!|||||------------x-x-x-x------
nakama         | {"level":"error","ts":"2020-05-15T03:46:25.231Z","msg":"Error running Matchmaker Matched hook.","error":"Error running runtime Matchmaker Matched hook: /nakama/data/modules/hooks.lua:6: error creating match: /nakama/data/modules/match.lua:7: attempt to call a non-function object\nstack traceback:\n\t/nakama/data/modules/match.lua:7: in main chunk\n\t[G]: ?\nstack traceback:\n\t[G]: in function 'match_create'\n\t/nakama/data/modules/hooks.lua:6: in main chunk\n\t[G]: ?","stacktrace":"github.com/heroiclabs/nakama/v2/server.(*Pipeline).matchmakerAdd\n\tgithub.com/heroiclabs/nakama/v2/server/pipeline_matchmaker.go:85\ngithub.com/heroiclabs/nakama/v2/server.(*Pipeline).ProcessRequest\n\tgithub.com/heroiclabs/nakama/v2/server/pipeline.go:154\ngithub.com/heroiclabs/nakama/v2/server.(*sessionWS).Consume\n\tgithub.com/heroiclabs/nakama/v2/server/session_ws.go:243\ngithub.com/heroiclabs/nakama/v2/server.NewSocketWsAcceptor.func2\n\tgithub.com/heroiclabs/nakama/v2/server/socket_ws.go:100\nnet/http.HandlerFunc.ServeHTTP\n\tnet/http/server.go:2012\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\tgithub.com/gorilla/mux@v1.7.4/mux.go:210\ngithub.com/gorilla/handlers.(*cors).ServeHTTP\n\tgithub.com/gorilla/handlers@v1.4.2/cors.go:138\nnet/http.serverHandler.ServeHTTP\n\tnet/http/server.go:2807\nnet/http.(*conn).serve\n\tnet/http/server.go:1895"}

Can you confirm what version of the server you are using?

I was using 2.11.1, it was created using this docker-compose file:

version: '3'
services:
  cockroachdb:
    container_name: cockroachdb
    image: cockroachdb/cockroach:v19.2.5
    command: start --insecure --store=attrs=ssd,path=/var/lib/cockroach/
    restart: always
    volumes:
      - data:/var/lib/cockroach
    expose:
      - "8080"
      - "26257"
    ports:
      - "26257:26257"
      - "8080:8080"
  nakama:
    container_name: nakama
    image: heroiclabs/nakama:2.11.1
    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
          /nakama/nakama migrate up --database.address root@cockroachdb:26257 &&
          exec /nakama/nakama --name nakama1 --database.address root@cockroachdb:26257
    restart: always
    links:
      - "cockroachdb:db"
    depends_on:
      - cockroachdb
    volumes:
            - ./nakama/data:/nakama/data
    expose:
      - "7349"
      - "7350"
      - "7351"
    ports:
      - "7349:7349"
      - "7350:7350"
      - "7351:7351"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:7350/"]
      interval: 10s
      timeout: 5s
      retries: 5
volumes:
  data:

You’re trying to call os.execute which is not available in the embedded Lua runtime, read more about it in the docs.

If you need to execute another application you can connect to it over a socket or HTTP request, or you can use the Go runtime which does not have the sandbox restrictions of the Lua runtime.

1 Like