• How to call my C++ dll in Garry's Mod? (It works well in SciTE, but doesn't in Garry's Mod)
    28 replies, posted
Hi, I am trying to take the Garry's Mod as the develop platform, so I hope to load my dll built in C++. My lua scripts works very well in SciTE, but It doesn't work when I compile the lua script in Garry's Mod. So anyone can give me hand? Thanks!
Erm, are you trolling? Or using the wrong terminology? You don't compile lua scripts, SciTE is just a text editor with no debugging features and gar... I quit.
[QUOTE=KillerLUA;34392081]Erm, are you trolling? Or using the wrong terminology? You don't compile lua scripts, SciTE is just a text editor with no debugging features and gar... I quit.[/QUOTE] Oh! I am serious! It can really compile and run lua truncks! And I try to call my C DLL named hello.dll with" require("hello")" And it can run in SciTE (SciTE Version 2.24 Feb 25 2011 20:52:45). I save the trunck in a LUA file name "aat.lua", but when I load the file using "lua_openscript", there is error: error loading module 'hello' from file 'd:\program files (x86)\steam\steamapps\blacknightzz\garrysmod\garrysmod\lua\includes\modules\gm_hello.dll'. In additon, the operation should be legal according to the tutorial "http://wiki.garrysmod.com/?title=GModInterface". So could you help me to solve this problem? Thanks a lot!
[QUOTE=Joe840120;34392384]Oh! I am serious! It can really compile and run lua truncks! And I try to call my C DLL named hello.dll with" require("hello")" And it can run in SciTE (SciTE Version 2.24 Feb 25 2011 20:52:45). I save the trunck in a LUA file name "aat.lua", but when I load the file using "lua_openscript", there is error: error loading module 'hello' from file 'd:\program files (x86)\steam\steamapps\blacknightzz\garrysmod\garrysmod\lua\includes\modules\gm_hello.dll'. In additon, the operation should be legal according to the tutorial "http://wiki.garrysmod.com/?title=GModInterface". So could you help me to solve this problem? Thanks a lot![/QUOTE] wait, why are you using a .dll file? Can't you simply use lua?
I need to connect this engine with other programming tools for example labView, matlab and C++! [editline]25th January 2012[/editline] [QUOTE=ExplosiveCheese;34392425]wait, why are you using a .dll file? Can't you simply use lua?[/QUOTE] At present, I just test the simple code! But I failed!
[QUOTE=Joe840120;34392512]I need to connect this engine with other programming tools for example labView, matlab and C++! [editline]25th January 2012[/editline] At present, I just test the simple code! But I failed![/QUOTE] Well oh my God! We must help! Can you upload the source to your module! So we can help!
$10 says he hasn't stated an entry/exit point
[QUOTE=somescripter;34392585]Well oh my God! We must help! Can you upload the source to your module! So we can help![/QUOTE] Sorry! I am a beginner for Garry's Mod! Which module do you mean?
I was hoping it was going to be something hilarious like: [cpp] void main() { function PlayerSpawn() player.GetAll().Kill().Hook.Add.System; end; } [/cpp]
He means the dll you are calling require on
[QUOTE=Bawbag;34392628]$10 says he hasn't stated an entry/exit point[/QUOTE] Is it very critical for loading dll in Garry's Mod?
yes GMOD_MODULE(Init, Shutdown);
[QUOTE=Bawbag;34392736]yes GMOD_MODULE(Init, Shutdown);[/QUOTE] Oh! Thank you very much! I will try again! [editline]25th January 2012[/editline] [QUOTE=somescripter;34392669]I was hoping it was going to be something hilarious like: [cpp] void main() { function PlayerSpawn() player.GetAll().Kill().Hook.Add.System; end; } [/cpp][/QUOTE] My code is very simple! #include <windows.h> #include <iostream> #include "math.h" #include <string.h> #include <errno.h> extern "C"{ #include "lua.h" #include "lualib.h" #include "lauxlib.h" } #include "lib1.h" #pragma comment(lib,"lua5.1.lib") static int helloworld(lua_State* L) { MessageBox(NULL,L"Hello World",L"Start",MB_OK); return 0; } static const luaL_reg my [] = { {"hello",helloworld}, {NULL, NULL} }; extern "C" int _declspec(dllexport) my(lua_State* L) { luaL_openlib(L, "my", my, 0); return 1; }
This is the wrong forum to come to for binding lua functions to your C/C++ program.
wtf don't use garrysmod as a development platform what are you even doing
[QUOTE=Hentie;34393090]This is the wrong forum to come to for binding lua functions to your C/C++ program.[/QUOTE] But which is better one?
the programming forum.
[url]http://www.facepunch.com/forums/70[/url]
[QUOTE=Joe840120;34393339]But which is better one?[/QUOTE] [url]http://www.facepunch.com/threads/1152030/10[/url] Don't go to the Binary Modules section, that's for binding lua functions for the game Garry's Mod and not for your own program.
Please have a look at [url]http://wiki.garrysmod.com/?title=GLuaModule[/url] Gmod modules aren't default Lua modules, and you can't use the lua5.1 headers as the lua for gmod is modified (and because garry swapped the order of elements in the luastate struct)
[QUOTE=KillerLUA;34392081] You don't compile lua scripts, SciTE is just a text editor with no debugging features and gar... I quit.[/QUOTE] You can (in a way) if you want. Actually helps with execution speeds, apparently. [url]http://www.facepunch.com/threads/1157878[/url] [url]http://luajit.org/luajit.html[/url]
-snip or maybe he is- :o
[QUOTE=wizardsbane;34404301]You can (in a way) if you want. Actually helps with execution speeds, apparently. [url]http://www.facepunch.com/threads/1157878[/url] [url]http://luajit.org/luajit.html[/url][/QUOTE] LuaJIT is in no way related to pre-compiled code ...
[QUOTE=James xX;34417441]LuaJIT is in no way related to pre-compiled code ...[/QUOTE] He never talked about pre-compiled code, he said "you don't compile Lua scripts", but you can. A just-in-time [U]compiler[/U] wouldn't be called such if it didn't, in fact, compile, and it does. Also, you [I]can[/I] compile actual Lua scripts, although their usage would be outside of Garry's Mod I think.
[QUOTE=wizardsbane;34417679]He never talked about pre-compiled code, he said "you don't compile Lua scripts", but you can. A just-in-time [U]compiler[/U] wouldn't be called such if it didn't, in fact, compile, and it does. Also, you [I]can[/I] compile actual Lua scripts, although their usage would be outside of Garry's Mod I think.[/QUOTE] You can compile lua, it's even got functions ported to garry's mod. When you say "He never talked about pre-compiled code", You obviously didn't read my post. In case after a couple re-reads of my post , it still hasn't got through to you, let me cut this up for you : You [B]can[/B] compile code, Lua [B]gets[/B] compiled into byte code before running, LuaJIT [B]only[/B] compiles things just before they are meant to run ( hence the speed boost ). What i was disagreeing with in his post was the fact that he made the LuaJIT module port seem like a compiler, as in the type of compiler that will output a file ( which isn't the case. )
Thank you! But I cannot open the link at present! [QUOTE=OldFusion;34399904]Please have a look at [url]http://wiki.garrysmod.com/?title=GLuaModule[/url] Gmod modules aren't default Lua modules, and you can't use the lua5.1 headers as the lua for gmod is modified (and because garry swapped the order of elements in the luastate struct)[/QUOTE]
Yeah unfortunately the wiki is down, I'll see if I can find the page anywhere
dude nice post [highlight](User was banned for this post ("dumb bump" - postal))[/highlight]
Sorry, you need to Log In to post a reply to this thread.