Skip to content

Commit 205220f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into tests-bass-experimental
2 parents a438bae + 0e70032 commit 205220f

File tree

164 files changed

+43185
-178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+43185
-178
lines changed

.github/workflows/compile-luajit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- 'libs/liblua_shared_lib_*'
99
- 'libs/lua_shared_lib_*'
1010
- 'luajit/**'
11+
- '!gmod-luajit/**'
1112

1213
jobs:
1314
build-windows-64:

README.md

Lines changed: 141 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ This is done by first deleting the current `gmsv_holylib_linux[64].so` and then
8080
8181
## Next Update
8282
\- [+] Any files in `lua/autorun/_holylua/` are loaded by HolyLib on startup.<br>
83-
\- [+] Added a new modules `luathreads`, `networkthreading`, `soundscape`<br>
83+
\- [+] Added a new modules `luathreads`, `networkthreading`, `soundscape`, `luagc`, `nw2`<br>
8484
\- [+] Added `NS_` enums to `gameserver` module.<br>
8585
\- [+] Added missing `CNetChan:Shutdown` function to the `gameserver` module.<br>
8686
\- [+] Added LZ4 compression for newly implemented net channel.<br>
@@ -176,6 +176,8 @@ https://github.com/RaphaelIT7/gmod-holylib/compare/Release0.7...main
176176
\- [+] Added `directData` argument to `VoiceStream:GetData`, `VoiceStream:GetIndex`, `VoiceStream:SetIndex` and `VoiceStream:SetData`<br>
177177
\- [+] Added overflow checks for `gameserver.BroadcastMessage`, `CNetChan:SendMessage` and `CBaseClient:SendNetMsg` when you try to use a overflowed buffer<br>
178178
\- [+] Added a few more arguments to `HolyLib:OnPhysicsLag` like `phys1`, `phys2`, `recalcPhys`, `callerFunction` and the arguments `ent1` & `ent2` were removed since you can call `PhysObj:GetEntity`<br>
179+
\- [+] Added `steamworks.GetGameServerSteamID` to the `steamworks` module.<br>
180+
\- [+] Added `HolyLib:OnLuaRunString` hook to the `holylib` module.<br>
179181
\- [#] Fixed `addonsystem.ShouldMount` & `addonsystem.SetShouldMount` `workshopID` arguments being a number when they should have been a string.<br>
180182
\- [#] Changed `VoiceData:GetUncompressedData` to now returns a statusCode/a number on failure instead of possibly returning a garbage string.<br>
181183
\- [#] Limited `HttpServer:SetName` to have a length limit of `64` characters.<br>
@@ -188,6 +190,8 @@ https://github.com/RaphaelIT7/gmod-holylib/compare/Release0.7...main
188190
\- [#] Changed arguments and return value of `HolyLib:PostEntityConstructor`<br>
189191
\- [#] Changed `pvs.AddEntityToTransmit` to only work inside `HolyLib:PreCheckTransmit` due to safety & performance reasons<br>
190192
\- [#] Changed `HolyLib:[Pre/Post]CheckTransmit` hooks to be disabled by default needing to be now enabled using `pvs.Enable[Pre/Post]TransmitHook`<br>
193+
\- [#] Changed `HttpServer:[Get/Put/Post/OtherShit]` callback return value to be flipped, return `false` to mark a request as `NOT` handled, return `true` to mark it as handled<br>
194+
\- [#] Fixed `networking` module partially not working without the `pvs` module - it internally had depended on it.<br>
191195
\- [-] Removed `VoiceData:GetUncompressedData` decompress size argument<br>
192196
\- [-] Removed `CBaseClient:Transmit` third argument `fragments`.<br>
193197
\- [-] Removed `gameserver.CalculateCPUUsage` and `gameserver.ApproximateProcessMemoryUsage` since they never worked.<br>
@@ -3897,12 +3901,16 @@ end, true)
38973901

38983902
If you enable the IP Whitelist, only requests sent by connected players are processed.<br>
38993903

3900-
#### HttpServer:Get(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3901-
#### HttpServer:Put(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3902-
#### HttpServer:Post(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3903-
#### HttpServer:Patch(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3904-
#### HttpServer:Delete(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3905-
#### HttpServer:Options(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3904+
> [!NOTE]
3905+
> If you return `false` you mark a request as **not** handled.<br>
3906+
> This means that the delay will **not** be responded to until you call `HttpRequest:MarkHandled`<br>
3907+
3908+
#### bool(handled) HttpServer:Get(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3909+
#### bool(handled) HttpServer:Put(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3910+
#### bool(handled) HttpServer:Post(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3911+
#### bool(handled) HttpServer:Patch(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3912+
#### bool(handled) HttpServer:Delete(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
3913+
#### bool(handled) HttpServer:Options(string path, function (HttpRequest, HttpResponse), bool ipWhitelist)
39063914

39073915
### HttpRequest
39083916
A incoming Http Request.
@@ -5183,6 +5191,126 @@ If enabled, some packets will be processed by the networking thread instead of t
51835191
> [!NOTE]
51845192
> This can cause the `HolyLib:ProcessConnectionlessPacket` to not be called for the affected packets!
51855193
5194+
## luagc
5195+
5196+
### Functions
5197+
5198+
#### number luagc.GetGCCount(any targetObject = nil)
5199+
Returns the total count of GC objects.<br>
5200+
If given a `targetObject` object, it will count up all GCobjects until it reached the `targetObject` after which it'll stop.<br>
5201+
(the `targetObject` **won't** be included in the result!)
5202+
5203+
#### table luagc.GetReferences(any object)
5204+
Returns a table containing **all** GCObjects that have a reference stored to the given object.<br>
5205+
5206+
#### table luagc.GetContainingReferences(any object, bool recursive = false, table ignoreGCObjects = nil)
5207+
Returns all GCobjects that the given object stores.<br>
5208+
Can be recursive to include all GCobjects referenced by all child objects.<br>
5209+
ignoreGCObjects - A **sequential** table inside which you can provide GC objects that should be ignored like the global table/`_G`<br>
5210+
5211+
#### table luagc.GetAllGCObjects(any targetObject = nil)
5212+
Returns a table containing all GCobjects.<br>
5213+
If given a `targetObject` object, it will return all GCobjects until it reached the `targetObject` after which it'll stop.<br>
5214+
(the `targetObject` **won't** be included in the result!)
5215+
5216+
The GClist **always** goes from newest to oldest GCobjects due to how the GCobjects are chained.<br>
5217+
5218+
> [!NOTE]
5219+
> This function itself create a table which is why doing<br>
5220+
> `luagc.GetAllGCObjects(luagc.GetCurrentGCHeadObject())`<br>
5221+
> Will always have 1 object - which is the returned table.<br>
5222+
> You can do `table.remove(gcList, 1)` to remove the first entry to get rid of it.<br>
5223+
5224+
Example usage:
5225+
```lua
5226+
collectgarbage("stop") -- to not modify gc list
5227+
local gcHead = luagc.GetCurrentGCHeadObject()
5228+
5229+
function Example() -- 1 GCfunction
5230+
return {}
5231+
end
5232+
Example() -- Returns 1 GCtable
5233+
debug.setfenv(Example, {}) -- to avoid printing _G below - also creates 1 GCtable
5234+
5235+
-- Now print all new GC objects created by our code above
5236+
local gcList = luagc.GetAllGCObjects(gcHead)
5237+
table.remove(gcList, 1) -- remove the gcList table from itself since it included as the first entry.
5238+
5239+
for _, gcObject in ipairs(gcList) do
5240+
print("object: " .. tostring(gcObject) .. " (type: " .. type(gcObject) .. ")")
5241+
end
5242+
```
5243+
5244+
Result:
5245+
```lua
5246+
object: table: 0xf0b9fdea (type: table)
5247+
object: table: 0xf09ffc3a (type: table)
5248+
object: function: 0xf0bf9cb2 (type: function)
5249+
```
5250+
5251+
#### any luagc.GetCurrentGCHeadObject()
5252+
Returns the current GCobject that's at the head of the list.<br>
5253+
5254+
> [!NOTE]
5255+
> The head object is **always** the newest one.
5256+
5257+
#### table luagc.GetFormattedGCObjectInfo(any object)
5258+
Returns a nicely formatted table showing which fields store which GC references for the given object.<br>
5259+
5260+
> [!NOTE]
5261+
> Fields are not consistent and can be **nil** always check if a field exists!
5262+
5263+
Example:
5264+
```lua
5265+
function test()
5266+
end
5267+
debug.setfenv(test, {hai = ":3"})
5268+
5269+
local formatted = luagc.GetFormattedGCObjectInfo(test)
5270+
PrintTable(formatted)
5271+
PrintTable(formatted.proto) -- Let's also see the proto
5272+
```
5273+
5274+
Output:
5275+
```lua
5276+
["environment"]:
5277+
["hai"] = :3
5278+
["object"] = function: 0xf09e29f2
5279+
["proto"] = proto: 0xf0898ae2
5280+
["type"] = function
5281+
["upvalues"]:
5282+
5283+
["constants"]:
5284+
["name"] = @lua_run
5285+
["object"] = proto: 0xefabbfb2
5286+
["type"] = proto
5287+
```
5288+
5289+
#### number luagc.GetSizeOfGCObject(any object, bool recursive = false, table ignoreGCObjects = nil)
5290+
Returns the memory size of the given object.<br>
5291+
If recursive is set, then the size of referenced objects is added to the total result.<br>
5292+
ignoreGCObjects - A **sequential** table inside which you can provide GC objects that should be ignored like the global table/`_G`<br>
5293+
5294+
## nw2
5295+
Simple purpose - to fix NW2Vars from breaking.<br>
5296+
This bug happens under the following scenario:<br>
5297+
5298+
An new entity spawns the **first time** / no entity of it's class was created before.<br>
5299+
Then on this new entity - a NW2Var is set with it's creation.<br>
5300+
5301+
Now the issue is - when the engine packs the entity for networking, it'll store the packed data as the baseline.<br>
5302+
This **includes** NW2Vars and this baseline is used for all entities of the same class meaning the NW2Var would be present for all of them.<br>
5303+
This storing into the base line **only** happens once for the first time an entitiy was created - this is per entity class!<br>
5304+
(C++ entities - Lua's all share one class meaning this bug would apply a NW2Var to all of them!)<br>
5305+
5306+
Now what this module does - it prevents writing NW2Vars into the baseline ensuring they won't be applied to all entites of the same class.<br>
5307+
5308+
> [!NOTE]
5309+
> The bug still exists clientside though seems to be rarer / variables don't seem to actually change?<br>
5310+
> There still seems to be invalid proxy calls though nothing much I can do about that.<br>
5311+
> This definetly needs more testing though it should be an improvement.<br>
5312+
5313+
51865314
# Unfinished Modules
51875315

51885316
## serverplugins
@@ -5199,6 +5327,12 @@ Supports: Linux32 | Linux64<br>
51995327
> [!NOTE]
52005328
> Windows doesn't have plugins / we won't support it there.<br>
52015329
5330+
## net
5331+
Was meant to provide extended functions like net.Seek and so on.
5332+
5333+
## networkingreplacement
5334+
Will implement the entire packed entity code and snapshot stuff with our own implementation to hopefully achieve better performance.
5335+
52025336
# Issues implemented / fixed
52035337
`gameevent.GetListeners` -> https://github.com/Facepunch/garrysmod-requests/issues/2377<br>
52045338
`stringtable.FindTable("modelprecache"):GetNumStrings()` -> https://github.com/Facepunch/garrysmod-requests/issues/82<br>

gmod-luajit/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Both versions:<br>
2+
`LUA_IDSIZE` raised to `128`<br>
3+
4+
GMod's 64x Version (most likely): https://github.com/LuaJIT/LuaJIT/tree/66c1614828d0041baece3ab2002763f2a2fd83b3<br>
5+
Defs: `LUAJIT_ENABLE_GC64 LUAJIT_DISABLE_FFI`<br>
6+
Thx Spar <3<br>
7+
8+
GMod's 32x Version - unknown. Latest 2.0 commit used for now.<br>

gmod-luajit/luajit.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#define LUAJIT_ENABLE_GC64
2+
#define LUAJIT_DISABLE_FFI
3+
extern "C"
4+
{
5+
#if PLATFORM_64BITS
6+
#include "luajit21/lj_obj.h"
7+
#else
8+
#include "luajit20/lj_obj.h"
9+
#endif
10+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
** LuaJIT VM builder.
3+
** Copyright (C) 2005-2025 Mike Pall. See Copyright Notice in luajit.h
4+
*/
5+
6+
#ifndef _BUILDVM_H
7+
#define _BUILDVM_H
8+
9+
#include <sys/types.h>
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
#include <string.h>
13+
#include <errno.h>
14+
15+
#include "lj_def.h"
16+
#include "lj_arch.h"
17+
18+
/* Hardcoded limits. Increase as needed. */
19+
#define BUILD_MAX_RELOC 200 /* Max. number of relocations. */
20+
#define BUILD_MAX_FOLD 4096 /* Max. number of fold rules. */
21+
22+
/* Prefix for scanned library definitions. */
23+
#define LIBDEF_PREFIX "LJLIB_"
24+
25+
/* Prefix for scanned fold definitions. */
26+
#define FOLDDEF_PREFIX "LJFOLD"
27+
28+
/* Prefixes for generated labels. */
29+
#define LABEL_PREFIX "lj_"
30+
#define LABEL_PREFIX_BC LABEL_PREFIX "BC_"
31+
#define LABEL_PREFIX_FF LABEL_PREFIX "ff_"
32+
#define LABEL_PREFIX_CF LABEL_PREFIX "cf_"
33+
#define LABEL_PREFIX_FFH LABEL_PREFIX "ffh_"
34+
#define LABEL_PREFIX_LIBCF LABEL_PREFIX "lib_cf_"
35+
#define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_"
36+
37+
/* Forward declaration. */
38+
struct dasm_State;
39+
40+
/* Build modes. */
41+
#define BUILDDEF(_) \
42+
_(elfasm) _(coffasm) _(machasm) _(peobj) _(raw) \
43+
_(bcdef) _(ffdef) _(libdef) _(recdef) _(vmdef) \
44+
_(folddef)
45+
46+
typedef enum {
47+
#define BUILDENUM(name) BUILD_##name,
48+
BUILDDEF(BUILDENUM)
49+
#undef BUILDENUM
50+
BUILD__MAX
51+
} BuildMode;
52+
53+
/* Code relocation. */
54+
typedef struct BuildReloc {
55+
int32_t ofs;
56+
int sym;
57+
int type;
58+
} BuildReloc;
59+
60+
typedef struct BuildSym {
61+
const char *name;
62+
int32_t ofs;
63+
} BuildSym;
64+
65+
/* Build context structure. */
66+
typedef struct BuildCtx {
67+
/* DynASM state pointer. Should be first member. */
68+
struct dasm_State *D;
69+
/* Parsed command line. */
70+
BuildMode mode;
71+
FILE *fp;
72+
const char *outname;
73+
char **args;
74+
/* Code and symbols generated by DynASM. */
75+
uint8_t *code;
76+
size_t codesz;
77+
int npc, nglob, nsym, nreloc, nrelocsym;
78+
void **glob;
79+
BuildSym *sym;
80+
const char **relocsym;
81+
int32_t *bc_ofs;
82+
const char *beginsym;
83+
/* Strings generated by DynASM. */
84+
const char *const *globnames;
85+
const char *dasm_ident;
86+
const char *dasm_arch;
87+
/* Relocations. */
88+
BuildReloc reloc[BUILD_MAX_RELOC];
89+
} BuildCtx;
90+
91+
extern void owrite(BuildCtx *ctx, const void *ptr, size_t sz);
92+
extern void emit_asm(BuildCtx *ctx);
93+
extern void emit_peobj(BuildCtx *ctx);
94+
extern void emit_lib(BuildCtx *ctx);
95+
extern void emit_fold(BuildCtx *ctx);
96+
97+
extern const char *const bc_names[];
98+
extern const char *const ir_names[];
99+
extern const char *const irt_names[];
100+
extern const char *const irfpm_names[];
101+
extern const char *const irfield_names[];
102+
extern const char *const ircall_names[];
103+
104+
#endif

0 commit comments

Comments
 (0)