Skip to content

Implement Lua - #45

Draft
RaphaelIT7 wants to merge 16 commits into
mainfrom
luajit
Draft

Implement Lua#45
RaphaelIT7 wants to merge 16 commits into
mainfrom
luajit

Conversation

@RaphaelIT7

Copy link
Copy Markdown
Collaborator

The C++ side should be somewhat implemented now, though I still suck at C# and before I make a mess it would probably be best to get some feedback of which functions for FFI to add and what the best way to bridge C# & C++ would be

@RaphaelIT7
RaphaelIT7 requested a review from marchc1 December 1, 2025 10:01
@RaphaelIT7 RaphaelIT7 added the Enhancement New feature or request label Dec 1, 2025
@The404Studios

Copy link
Copy Markdown

fyi, I think this is the right approach. LuaJIT really wants to stay native and in-process for hot paths. Keeping lua_State, GC, userdata, hooks, and math types in a small native core with a boring C ABI, and letting C# just orchestrate and call into it synchronously, feels like the cleanest and most Source-accurate way to do this. That keeps the bridge minimal and avoids turning FFI into a mess.

Comment thread Lua.JIT/luajit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not a submodule? https://github.com/luajit/luajit

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are changes made to LuaJIT that would have to be done in order to be compatible with Garry's Mod's flavor of Lua, so it can't just be a LuaJIT submodule

@penggrin12 penggrin12 Jul 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are changes made to LuaJIT that would have to be done in order to be compatible with Garry's Mod's flavor of Lua, so it can't just be a LuaJIT submodule

submodule a fork of our own?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are changes made to LuaJIT that would have to be done in order to be compatible with Garry's Mod's flavor of Lua, so it can't just be a LuaJIT submodule

submodule a fork of our own?

Yeah I would prefer that. I need to talk with @RaphaelIT7 still about if he wants to continue leading this effort or not in general. We're a lot further along now but I still would want to continue focusing on engine implementations before focusing too much on Lua

Comment thread Source.Engine/EngineAPI.cs Outdated
@@ -46,6 +46,10 @@ public IEngineAPI.Result RunListenServer() {
public void SetStartupInfo(in StartupInfo info) {
startupInfo = info;
Sys.TextMode = info.TextMode;
// RaphaelIT7: Excuse me for throwing this in here, but I don't have a copy of gmod on my laptop! lemme test in peace >:3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could put it behind a flag of some kind (like a preprocessor ifdef)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this? looks like something that should be gitignored

Comment thread Lua.Shared/Types.h
Comment on lines +3 to +5
namespace Type
{
enum

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason not to use a class enum?

Comment thread Lua.Shared/PooledStrings.h Outdated
Comment thread Lua.Shared/csharpbridge.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other header files dont start with a lowercase letter

@marchc1

marchc1 commented Jul 26, 2026

Copy link
Copy Markdown
Owner

@penggrin12 I would probably ignore this PR if I were you as I imagine @RaphaelIT7 would want to do this differently now (in general I need to make a tracking issue for Lua implementation, since theres quite a few areas we could improve over Garry's Mod but would need to be careful)

@RaphaelIT7

Copy link
Copy Markdown
Collaborator Author

I probably won't be doing much here, as I don't have the time or patience to also further learn C# to figure this out.
Anyone can take over this- I'm still open to help/answer any questions for GMod as always on discord.
I can probably keep an LuaJIT fork maintained- and probably even backport a few changes from my own Engine's fork so that Source.NET could use sandboxed FFI once it's done (I wrote with @marchc1 about that a bit already xd)

@RaphaelIT7 RaphaelIT7 added the Help Wanted Extra attention is needed label Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request Help Wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants