Techmo Posted July 27, 2018 Share Posted July 27, 2018 (edited) I finally decided to start the gmod standard library. This is a library to be used when creating binary modules for gmod servers/clients. It is a collection of useful functions that make the development of binary modules physiologically possible. I just started it today, and plan to add a lot more features. I'll post a link to the api documentation once I finish writing it. When complete, this library will allow anything that can be done in lua to be implemented in c++. The current set of functions: A simple function to print a string to the console. Versions for both string types exist. void PrintC(const char* msg); void PrintC(std::string& msg); Example: PrintC("Hello World!"); A simple function to print a string to the console with the specified color. Versions for both string types exist. void PrintC(const char* msg, Color& c); void PrintC(std::string msg, Color& c); Example: PrintC("Hello World!", Color(255, 0, 0, 255)); Example: PrintC("Hello World!", COLOR_RED); A simple utility to quickly concatenate strings. std::string formstring(); Example: PrintC(formstring("Player ", player_name, " has joined team ", team_number)); A function to execute a console command. void RunCommand(lua_State* state, const char* cmd); Example: RunCommand(LUA, "npc_create npc_citizen"); A function to compile a string containing lua code into lua bytecode, then execute it. void RunLua(lua_State* state, const char* lua); Example: const char* code = "local players = player.GetAll()" "PrintTable(players)"; RunLua(LUA, code); A function to register functions written in c++, and make them available for use in Garry's Mod lua. void RegisterFunction(lua_State* state, const char* name, CFunc& func); Example: int SendToConsole(lua_State* state) { if(LUA->GetType(1) == Type::STRING) { PrintC(formstring("[Test Function]: ", LUA->GetString(1)); } return 1; } ... RegisterFunction(LUA, "SendToConsole", SendToConsole); In Progress: A function to register a c++ function into a game event hook. void Hook(lua_State* state, const char* hook, const char* name, GarrysMod::Lua::CFunc& func); Example: Hook(LUA, "PlayerSpawn", "awesome_spawnhandler", PlayerSpawnHandler); Edited July 28, 2018 by Techmo 1 Quote Link to comment Share on other sites More sharing options...
Techmo Posted July 28, 2018 Author Share Posted July 28, 2018 I'm not posting the source or .lib until I think this library is more useful. However, If you want to use it, or are just curious about the code, send me a message and i'd be happy to share it with you. Quote Link to comment Share on other sites More sharing options...
Nightstar_91 Posted July 28, 2018 Share Posted July 28, 2018 that pretty cool but can you do this? 1 Quote Link to comment Share on other sites More sharing options...
Techmo Posted July 28, 2018 Author Share Posted July 28, 2018 right click -> inspect Quote Link to comment Share on other sites More sharing options...
Boxsnake Posted July 28, 2018 Share Posted July 28, 2018 that pretty cool but can you do this? shit post explain this library thing a bit more to me. what will it functions be for since you will add more features Quote Link to comment Share on other sites More sharing options...
Techmo Posted July 28, 2018 Author Share Posted July 28, 2018 (edited) shit post explain this library thing a bit more to me. what will it functions be for since you will add more features The functions will pretty much be the standard set of functions provided by Garry's Mod in glua, but implemented in c++ to make them faster. I also would like to add a few things that seem useful to me and make life easier. A library is pretty much a set of prewritten functions and code to be used by a developer. Writing directx, which is millions of lines of code, from scratch every time you make a new game would be tedious, so you use the directx library from microsoft. It's just the same thing here, i've done the work of implementing these functions in c++ to make things easier. If you were to use just the headers given to you from Garrys Mod, to print a message to the game chat would require the following: state->luabase->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB); state->luabase->GetField(-1, "PrintMessage"); // Get the function field from lua state->luabase->PushNumber(3); // Push a function parameter to the global stack. Print to game chat and console, from the Garry's mod HUD enumerations (3 = chat + console) state->luabase->PushString("hello players"); state->luabase->Call(2, 0); // Call with 2 arguments, expecting 0 return value state->luabase->Pop(); // Pop the values from the lua stack Using the library, the same could be done with: Broadcast(LUA, "hello players"); (I just implemented this in the library) Edited July 28, 2018 by Techmo 1 Quote Link to comment Share on other sites More sharing options...
Techmo Posted July 28, 2018 Author Share Posted July 28, 2018 I've created a website for the api docs if anyone feels like reading it. It will be updated as the library is updated. http://devmentality.com/docs/gstdlib Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.