Creating Binary Modules: Premake
Binary modules allow you to extend Lua's functionality using C++.
This page will teach you how to set up your IDE for compiling binary modules using Premake.
For help on interacting with the C Lua API once set up, refer to C Lua: Functions.
Dependencies
- Windows: Visual Studio 2015, Visual Studio 2017 or Visual Studio 2019 (Visual Studio 2022 has given me no issues)
- Linux: GCC (Included in
sudo apt install build-essential
if your distro supportsapt
) - macOS: Xcode (Use the GCC compiler) (Untested)
- A copy of the garrysmod_common repository
- Premake5 binaries
Project Setup
Create a new folder, name it anything you like. This will be your project's main folder. Put it somewhere you can get to it in the future.
Drop your copy of
garrysmod_common
into the project folder. If you downloaded a zip from github, extract its contents into the project folder.Drop the Premake5 binaries into the project folder.
Create a file named
premake5.lua
and paste the following in:- If you only intend to create server binaries, you can delete the section that says
serverside = false
. - Replace the name at
CreateWorkspace({name = "example"
with your project name i.e.name = "myprojectname"
- If you only intend to create server binaries, you can delete the section that says
- Create a folder named
source
and place an empty filemodule.cpp
in it. Copy this file's contents into it..
Your project folder should look like this:
In your system's command prompt, navigate to the project folder and run the following:
- Windows:
premake5.exe --os=windows --gmcommon=./garrysmod_common vs2022
(Replace vs2022 with your Visual Studio version i.e. vs2019) - Linux:
./premake5 --os=linux --gmcommon=./garrysmod_common gmake2
- macOS:
./premake5 --os=macosx --gmcommon=./garrysmod_common xcode4
This will create a projects
folder, which you should navigate to and start working in. If using Visual Studio, your solution file will be in here.
Naming & Location
The module files should be placed in the garrysmod/lua/bin/ folder.
The names differ between platform and Lua realm.
File name | Side | require(name) | Platform |
---|---|---|---|
gmsv_example_win32.dll |
Server | example | Windows x32 |
gmcl_example_win32.dll |
Client | example | Windows x32 |
gmsv_example_win64.dll |
Server | example | Windows x64 (x86-64 branch is required) |
gmcl_example_win64.dll |
Client | example | Windows x64 (x86-64 branch is required) |
gmsv_example_osx.dll |
Server | example | OSX (actually a .so file, just renamed) |
gmcl_example_osx.dll |
Client | example | OSX (actually a .so file, just renamed) |
gmsv_example_linux.dll |
Server | example | Linux x32 (actually a .so file, just renamed) |
gmcl_example_linux.dll |
Client | example | Linux x32 (actually a .so file, just renamed) |
gmsv_example_linux64.dll |
Server | example | Linux x64 (actually a .so file, just renamed; x86-64 branch is required) |
gmcl_example_linux64.dll |
Client | example | Linux x64 (actually a .so file, just renamed; x86-64 branch is required) |
gmsv_name_platform.dll