Call Go function from Lua

I started to develop my game using Lua, but I faced some limitations and I had to use golang. Do I have to change all my game logic to golang.

My question :
Is It possible for Lua to trigger Go functions and vice versa.

@Mohammed

develop my game using Lua, but I faced some limitations and I had to use golang

I’m curious what limitations did you encounter where you need to mix in some Go code to the project.

Is It possible for Lua to trigger Go functions and vice versa.

It’s not possible to call into functions between the two languages; this would be very complex to provide support for as you can imagine.

You could have some of your logic in Lua and other parts in Go. We have lots of game teams who have most of their code in Lua with a small amount in Go where needed. The server will load it all at startup so you can execute the RPC irrespective of which language it was written in.

@novabyte

I’m curious what limitations did you encounter where you need to mix in some Go code to the project.

Bitwise Operations

I want to use bitwise operators I am using int64 bits to keep the status of the player’s items like avatar/frame… (locked = 0, unlocked = 1)

I could not find a way to use Lua 5.1 to set bit / read bit

I am unlocking (set bit) after match end if an achievement is accomplished
A match handler (used LUA for the authoritative match) can’t call go as you explained. I can overcome this by making the client call the Go RPC to check if achievement is accomplished (not very convince!)

@Mohammed For bitwise operations in the Lua virtual machine we’ll need to add a backport for the bit32 Lua package to the game server. This is a good suggestion; please can you open a feature request on the GitHub repo. Thanks :pray:

@novabyte Done :+1:

1 Like

@Mohammed I had forgotten :man_facepalming: that we’d already added the "bit32" module as a backport into the Lua VM a while back. You can use it with these functions: https://www.lua.org/manual/5.2/manual.html#6.7