Skip to content

Commit 2efc916

Browse files
committed
Push code
1 parent a7ae78b commit 2efc916

File tree

9 files changed

+435
-0
lines changed

9 files changed

+435
-0
lines changed

.gitignore

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# User-specific files
2+
*.suo
3+
*.user
4+
*.userosscache
5+
*.sln.docstates
6+
7+
# Build results
8+
[Dd]ebug/
9+
[Dd]ebugPublic/
10+
[Rr]elease/
11+
[Rr]eleases/
12+
x64/
13+
x86/
14+
bld/
15+
[Bb]in/
16+
[Oo]bj/
17+
[Ll]og/
18+
19+
# Visual C++ cache files
20+
ipch/
21+
*.aps
22+
*.ncb
23+
*.opendb
24+
*.opensdf
25+
*.sdf
26+
*.cachefile
27+
*.VC.db
28+
*.VC.VC.opendb
29+
30+
# Visual Studio profiler
31+
*.psess
32+
*.vsp
33+
*.vspx
34+
*.sap
35+
36+
# Visual Studio cache files
37+
# files ending in .cache can be ignored
38+
*.[Cc]ache
39+
# but keep track of directories ending in .cache
40+
!*.[Cc]ache/
41+
42+
# Backup & report files from converting an old project file
43+
# to a newer Visual Studio version.
44+
_UpgradeReport_Files/
45+
Backup*/
46+
UpgradeLog*.XML
47+
UpgradeLog*.htm
48+
49+
# Premake generated project
50+
project/

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "LuaInterface"]
2+
path = LuaInterface
3+
url = [email protected]:glua/LuaInterface.git

LuaInterface/premake5.lua

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
defines "GMMODULE"
2+
includedirs "src"
3+
4+
local target_suffixes = {
5+
6+
bsd = "_linux",
7+
linux = "_linux",
8+
solaris = "_linux",
9+
windows = "_win32",
10+
macosx = "_osx" ,
11+
12+
}
13+
14+
local function GetTargetPrefix()
15+
16+
local name = project().name
17+
18+
if name:sub(1,3) == "gm_" or
19+
name:sub(1,5) == "gmsv_" or
20+
name:sub(1,5) == "gmcl_" then
21+
22+
return ""
23+
24+
end
25+
26+
return "gm_"
27+
28+
end
29+
30+
targetprefix ( GetTargetPrefix() )
31+
targetextension ".dll"
32+
targetsuffix ( target_suffixes[ os.get() ] )
33+
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
#ifndef GARRYSMOD_LUA_INTERFACE_H
3+
#define GARRYSMOD_LUA_INTERFACE_H
4+
5+
#include "Types.h"
6+
#include "LuaBase.h"
7+
#include "UserData.h"
8+
9+
10+
#ifdef GMMODULE
11+
12+
struct lua_State
13+
{
14+
unsigned char _ignore_this_common_lua_header_[69];
15+
GarrysMod::Lua::ILuaBase* luabase;
16+
};
17+
18+
#ifdef _WIN32
19+
#define DLL_EXPORT extern "C" __declspec( dllexport )
20+
#else
21+
#define DLL_EXPORT extern "C" __attribute__((visibility("default")))
22+
#endif
23+
24+
#define GMOD_MODULE_OPEN() DLL_EXPORT int gmod13_open( lua_State* state )
25+
#define GMOD_MODULE_CLOSE() DLL_EXPORT int gmod13_close( lua_State* state )
26+
27+
#define LUA state->luabase
28+
29+
#endif
30+
31+
#endif
32+
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
2+
#ifndef GARRYSMOD_LUA_LUABASE_H
3+
#define GARRYSMOD_LUA_LUABASE_H
4+
5+
#include <stddef.h>
6+
7+
struct lua_State;
8+
9+
namespace GarrysMod
10+
{
11+
namespace Lua
12+
{
13+
typedef int (*CFunc) (lua_State *L);
14+
15+
//
16+
// Access to raw Lua function calls
17+
//
18+
class ILuaBase
19+
{
20+
public:
21+
22+
virtual int Top( void ) = 0;
23+
virtual void Push( int iStackPos ) = 0;
24+
virtual void Pop( int iAmt = 1 ) = 0;
25+
virtual void GetTable( int iStackPos ) = 0;
26+
virtual void GetField( int iStackPos, const char* strName ) = 0;
27+
virtual void SetField( int iStackPos, const char* strName ) = 0;
28+
virtual void CreateTable() = 0;
29+
virtual void SetTable( int i ) = 0;
30+
virtual void SetMetaTable( int i ) = 0;
31+
virtual bool GetMetaTable( int i ) = 0;
32+
virtual void Call( int iArgs, int iResults ) = 0;
33+
virtual int PCall( int iArgs, int iResults, int iErrorFunc ) = 0;
34+
virtual int Equal( int iA, int iB ) = 0;
35+
virtual int RawEqual( int iA, int iB ) = 0;
36+
virtual void Insert( int iStackPos ) = 0;
37+
virtual void Remove( int iStackPos ) = 0;
38+
virtual int Next( int iStackPos ) = 0;
39+
virtual void* NewUserdata( unsigned int iSize ) = 0;
40+
virtual void ThrowError( const char* strError ) = 0;
41+
virtual void CheckType( int iStackPos, int iType ) = 0;
42+
virtual void ArgError( int iArgNum, const char* strMessage ) = 0;
43+
virtual void RawGet( int iStackPos ) = 0;
44+
virtual void RawSet( int iStackPos ) = 0;
45+
46+
virtual const char* GetString( int iStackPos = -1, unsigned int* iOutLen = NULL ) = 0;
47+
virtual double GetNumber( int iStackPos = -1 ) = 0;
48+
virtual bool GetBool( int iStackPos = -1 ) = 0;
49+
virtual CFunc GetCFunction( int iStackPos = -1 ) = 0;
50+
virtual void* GetUserdata( int iStackPos = -1 ) = 0;
51+
52+
virtual void PushNil() = 0;
53+
virtual void PushString( const char* val, unsigned int iLen = 0 ) = 0;
54+
virtual void PushNumber( double val ) = 0;
55+
virtual void PushBool( bool val ) = 0;
56+
virtual void PushCFunction( CFunc val ) = 0;
57+
virtual void PushCClosure( CFunc val, int iVars ) = 0;
58+
virtual void PushUserdata( void* ) = 0;
59+
60+
//
61+
// If you create a reference - don't forget to free it!
62+
//
63+
virtual int ReferenceCreate() = 0;
64+
virtual void ReferenceFree( int i ) = 0;
65+
virtual void ReferencePush( int i ) = 0;
66+
67+
//
68+
// Push a special value onto the top of the stack ( see below )
69+
//
70+
virtual void PushSpecial( int iType ) = 0;
71+
72+
//
73+
// For type enums see Types.h
74+
//
75+
virtual bool IsType( int iStackPos, int iType ) = 0;
76+
virtual int GetType( int iStackPos ) = 0;
77+
virtual const char* GetTypeName( int iType ) = 0;
78+
79+
//
80+
// Creates a new meta table of string and type and leaves it on the stack.
81+
// Will return the old meta table of this name if it already exists.
82+
//
83+
virtual void CreateMetaTableType( const char* strName, int iType ) = 0;
84+
85+
//
86+
// Like Get* but throws errors and returns if they're not of the expected type
87+
//
88+
virtual const char* CheckString( int iStackPos = -1 ) = 0;
89+
virtual double CheckNumber( int iStackPos = -1 ) = 0;
90+
91+
};
92+
93+
enum
94+
{
95+
SPECIAL_GLOB, // Global table
96+
SPECIAL_ENV, // Environment table
97+
SPECIAL_REG, // Registry table
98+
};
99+
}
100+
}
101+
102+
#endif
103+
+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
#ifndef GARRYSMOD_LUA_TYPES_H
3+
#define GARRYSMOD_LUA_TYPES_H
4+
5+
#ifdef ENTITY
6+
#undef ENTITY
7+
#endif
8+
9+
#ifdef VECTOR
10+
#undef VECTOR
11+
#endif
12+
13+
namespace GarrysMod
14+
{
15+
namespace Lua
16+
{
17+
namespace Type
18+
{
19+
enum
20+
{
21+
22+
INVALID = -1,
23+
NIL,
24+
BOOL,
25+
LIGHTUSERDATA,
26+
NUMBER,
27+
STRING,
28+
TABLE,
29+
FUNCTION,
30+
USERDATA,
31+
THREAD,
32+
33+
// UserData
34+
ENTITY,
35+
VECTOR,
36+
ANGLE,
37+
PHYSOBJ,
38+
SAVE,
39+
RESTORE,
40+
DAMAGEINFO,
41+
EFFECTDATA,
42+
MOVEDATA,
43+
RECIPIENTFILTER,
44+
USERCMD,
45+
SCRIPTEDVEHICLE,
46+
47+
// Client Only
48+
MATERIAL,
49+
PANEL,
50+
PARTICLE,
51+
PARTICLEEMITTER,
52+
TEXTURE,
53+
USERMSG,
54+
55+
CONVAR,
56+
IMESH,
57+
MATRIX,
58+
SOUND,
59+
PIXELVISHANDLE,
60+
DLIGHT,
61+
VIDEO,
62+
FILE,
63+
64+
COUNT
65+
};
66+
67+
static const char* Name[] =
68+
{
69+
"nil",
70+
"bool",
71+
"lightuserdata",
72+
"number",
73+
"string",
74+
"table",
75+
"function",
76+
"userdata",
77+
"thread",
78+
"entity",
79+
"vector",
80+
"angle",
81+
"physobj",
82+
"save",
83+
"restore",
84+
"damageinfo",
85+
"effectdata",
86+
"movedata",
87+
"recipientfilter",
88+
"usercmd",
89+
"vehicle",
90+
"material",
91+
"panel",
92+
"particle",
93+
"particleemitter",
94+
"texture",
95+
"usermsg",
96+
"convar",
97+
"mesh",
98+
"matrix",
99+
"sound",
100+
"pixelvishandle",
101+
"dlight",
102+
"video",
103+
"file",
104+
105+
0
106+
};
107+
}
108+
}
109+
}
110+
111+
#endif
112+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
#ifndef GARRYSMOD_LUA_USERDATA_H
3+
#define GARRYSMOD_LUA_USERDATA_H
4+
5+
namespace GarrysMod
6+
{
7+
namespace Lua
8+
{
9+
struct UserData
10+
{
11+
void* data;
12+
unsigned char type;
13+
};
14+
}
15+
}
16+
17+
#endif
18+

premake5.lua

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
solution "gm_securerandom"
2+
3+
language "C++"
4+
location "project"
5+
flags { "StaticRuntime", "C++11" }
6+
targetdir "bin"
7+
includedirs { "LuaInterface/src/" }
8+
architecture "x86"
9+
10+
configurations { "Release" }
11+
12+
configuration "Release"
13+
optimize "On"
14+
15+
project "gm_securerandom"
16+
defines { "GMMODULE" }
17+
files {
18+
"LuaInterface/src/GarrysMod/Lua/*.h",
19+
"src/*.h",
20+
"src/*.hpp",
21+
"src/*.hxx",
22+
"src/*.cpp",
23+
"src/*.cxx"
24+
}
25+
kind "SharedLib"

0 commit comments

Comments
 (0)