Garry's Mod Wiki

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

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"
PROJECT_GENERATOR_VERSION = 2 newoption({ trigger = "gmcommon", description = "Sets the path to the garrysmod_common (https://github.com/danielga/garrysmod_common) directory", value = "../garrysmod_common" }) local gmcommon = assert(_OPTIONS.gmcommon or os.getenv("GARRYSMOD_COMMON"), "you didn't provide a path to your garrysmod_common (https://github.com/danielga/garrysmod_common) directory") include(gmcommon) CreateWorkspace({name = "example", abi_compatible = false, path = "projects/" .. os.target() .. "/" .. _ACTION}) CreateProject({serverside = true, source_path = "source", manual_files = false}) IncludeLuaShared() IncludeScanning() IncludeDetouring() IncludeSDKCommon() IncludeSDKTier0() IncludeSDKTier1() CreateProject({serverside = false, source_path = "source", manual_files = true}) IncludeLuaShared() IncludeScanning() IncludeDetouring() IncludeSDKCommon() IncludeSDKTier0() IncludeSDKTier1() filter("system:windows") files({"source/win32/*.cpp", "source/win32/*.hpp"}) filter("system:linux or macosx") files({"source/posix/*.cpp", "source/posix/*.hpp"})

Your project folder should look like this:

explorer_ASnJkJMn31.png

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)
Menu state modules are categorized under gmsv_name_platform.dll