Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › MultiPlayer Game Hacks & Cheats › Steam Games Hacks & Cheats › Garry's Mod Hacks & Cheats › Garry's Mod Discussions & Help › How to load lua files and call runstring directly from lua_State

How to load lua files and call runstring directly from lua_State

Posts 1–12 of 12 · Page 1 of 1
Blue Kirby
Blue Kirby
How to load lua files and call runstring directly from lua_State
Loading lua files directly from ILuaInterface is shitty and has a lot of bullshit you don't need to deal with. There's a much better method.
Get your lua state however you normally would.

Code:
lua_State* state = g_Lua->GetLuaState();
Then make sure nothing is on the stack so you don't fuck anything up. Using loadstring and loadfile only puts the chunk on the stack, then you have to manually call it using call or pcall.

Note: pcall is extremely recommended. The difference is pcall is just protected call and will stop if there is an error.

Code:
if (!lua_gettop( state ))
{
 luaL_loadstring( state, "print(\"My message\")" );
 lua_pcall( state, 0, 0, 0 );

 luaL_loadfile( state, "file.lua" );
 lua_pcall( state, 0, 0, 0 );
}
It pops the chunk off the stack, so you don't need to worry with that.

Enjoy having tons of swag.
#1 · 12y ago
TheyCallMeDaz
TheyCallMeDaz
Hmm, whenever I tried this the lua state got destroyed and never got called. I'm probably being an idiot and doing it wrong, though.
#2 · 12y ago
AZ
Azrius
i'm a c++ baby, so excuse my stupid questions

what headers do you need to compile this? how do you get it into the game? injection or require?
#3 · 12y ago
LE
LennyPenny
https://******.com/garrynewman/gmod-module-base
#4 · 12y ago
AZ
Azrius
Quote Originally Posted by LennyPenny View Post
https://******.com/garrynewman/gmod-module-base
thanks, i'll assume that it's require then?
#5 · 12y ago
LE
LennyPenny
Quote Originally Posted by Azrius View Post
thanks, i'll assume that it's require then?
Sry, can't help with that. I tried making modules for gmod but I just can't get my head around all this "stack based development".
But this might help you getting round having to run a lua file with require http://www.mpgh.net/forum/713-garrys...s-require.html.
#6 · 12y ago
AZ
Azrius
Quote Originally Posted by LennyPenny View Post
Sry, can't help with that. I tried making modules for gmod but I just can't get my head around all this "stack based development".
But this might help you getting round having to run a lua file with require http://www.mpgh.net/forum/713-garrys...s-require.html.
thanks for trying to help anyway, i'll look into it
#7 · 12y ago
AN
animedad
Quote Originally Posted by Azrius View Post
thanks for trying to help anyway, i'll look into it
this is injection based not require based
(at least that's how i do it)
#8 · edited 12y ago · 12y ago
TheyCallMeDaz
TheyCallMeDaz
Lenny is an idiot, get the SDK from AlliedModders and compile it with BlackAwps backwards compat headers.
#9 · 12y ago
Blue Kirby
Blue Kirby
Quote Originally Posted by Azrius View Post
i'm a c++ baby, so excuse my stupid questions

what headers do you need to compile this? how do you get it into the game? injection or require?
Either one works, but I use injection. You need to use GetProcAddress for the lua functions.
#10 · 12y ago
AZ
Azrius
thanks guys, i really appreciate it
#11 · 12y ago
Blue Kirby
Blue Kirby
Quote Originally Posted by Azrius View Post
thanks guys, i really appreciate it
No problem. I'm always willing to teach those that want to learn.
#12 · 12y ago
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

  • [Question] How To Inject LTB FILES? And How To Swap GunsBy stanley2428 in Combat Arms Mod Discussion
    2Last post 16y ago
  • [Video] Loading lua files before autorun/clientBy Blue Kirby in Garry's Mod Discussions & Help
    14Last post 13y ago
  • How to use GSC files? and .iwd mods?By Armanii167 in Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    1Last post 15y ago
  • How to start Combat Arms from a file and not from the internetBy shooterman80 in Combat Arms Discussions
    20Last post 16y ago
  • How to add an attachment file and how to make CA hacks.By Klumzy in Programming Tutorial Requests
    2Last post 17y ago

Tags for this Thread

None