• gm_luajit - You wanted it
    18 replies, posted
[B]What this is[/B] I made this module as everyone was bitching about how slow it is and how much better GMod would be with it. So here it is, LuaJIT within Garry's Mod. [B]What can I do?[/B] For example you can run a loop that needs to be done fast within LuaJIT and return the result back to the GLua code, you can also call GLua functions from inside of the LuaJIT code which is however still pretty much experimental. [B]Example[/B] [lua]require'luajit' local ply = LocalPlayer() function testfunc(...) ply:Kill() end LuaJIT.Run( -- Code [[ -- All parameter are stored within _A print(_A) -- Calls the SetPos function GLuaCall(unpack(_A)) -- Calls testfunc within GLua GLuaCall("testfunc", unpack(_A)) print("Print from LuaJIT") ]], -- Parameters _R.Player.SetPos, ply, Vector(0, 0, 0) )[/lua] [B]Screenshots[/B] [url]http://dl.dropbox.com/u/29407915/luajit.png[/url] [url]http://dl.dropbox.com/u/29407915/luajit2.PNG[/url] [url]http://dl.dropbox.com/u/29407915/luajit3.png[/url] [B]Enough Chit-Chat, where is it[/B] I would like to call this module more or less alpha state as there's much planned and more to do. Code: [URL]https://mattmodules.googlecode.com/svn/trunk/gm_luajit[/URL] Windows Binary: [URL]https://mattmodules.googlecode.com/svn/trunk/gm_luajit/Release/gm_luajit.dll[/URL] Maybe someone can also compile this for Linux? I dislike Linux
Oh.
Is this in a separate thread?
[QUOTE=technicolour;34361350]Is this in a separate thread?[/QUOTE] No
Thank you my dear sir, now if you'll excuse me I have a few hundred lines of Lua to make awesomer also, food for thought, Wiremod + this
[QUOTE=Zeh Matt;34361033]-snip-[/QUOTE] The execute time made me nerdgasm. Make an interface wrapper and macros for this.
If somebody could assist you in making a Linux binary too, it would complete the awesomeness that is this. Good work, bud.
[QUOTE=Noi;34390509]hot, is there ffi support?[/QUOTE] That doesn't seem wanted as you could call any API
I fucking came. Thanks for doing this, it's already been of great use. The feel of running a sorting algorithm at compiled speed is exhilarating. So many possibilities.
Would calling glua functions in the luajit interface be slower? Man, if there was a way to grab the C function of each glua function and run that instead.
[QUOTE=Hentie;34439760]Would calling glua functions in the luajit interface be slower? Man, if there was a way to grab the C function of each glua function and run that instead.[/QUOTE] If you convince garry to give me the source I will be glad to help out with that
Can you make us a mac compile?
[QUOTE=_NewBee;34490768]Can you make us a mac compile?[/QUOTE] When I have finished what I planned for it I will do releases for all the platforms (I think). I will add new things this weekend such as adding metatables for Vector/Angle/Color to use at least some of them in LuaJIT directly
[QUOTE=Zeh Matt;34474190]If you convince garry to give me the source I will be glad to help out with that[/QUOTE] How about you start off with hooking lua_register and capture the functions that get pushed to the state by the engine.
[QUOTE=OldFusion;34493750]How about you start off with hooking lua_register and capture the functions that get pushed to the state by the engine.[/QUOTE] Garry doesn't use lua_register (and it doesn't exist in lua_shared), he uses his own CLuaLibrary class thing to register stuff. Globals have their own CLuaGlobalLibrary. The former uses ILuaInterface::Push to push the function, then SetMember to add it to the library table. Latter uses just SetGlobal(name, function). SetMember uses lua_pushvalue and lua_settable, SetGlobal uses lua_setfield with the global table index.
[QUOTE=OldFusion;34493750]How about you start off with hooking lua_register and capture the functions that get pushed to the state by the engine.[/QUOTE] The state is already created when the module is loaded and I'm not gonna get around modifying GMod lol
[QUOTE=Zeh Matt;34508032]The state is already created when the module is loaded and I'm not gonna get around modifying GMod lol[/QUOTE] No need for that. The Lua libraries and classes have to be initialized somewhere, of course. And as it happens, garry has conveniently placed them into two global arrays (well, actually CUtlVectors probably), which are then iterated in functions InitLuaLibraries and InitLuaClasses. Each CLuaLibrary and CLuaClass has an array of <string, function> structs, containing the method names and C functions. With this, you could for example sigscan InitLuaLibraries and InitLuaClasses, add offsets to the library and class lists, then iterate over those and save the C functions somewhere and use them. The functions could also be sigscanned. You can find them if you dig around client.dylib with IDA. Library functions' names are <library>____<function>, input____IsKeyDown for example. Class methods are called LC_<class>____<method>, LC_Angle____Forward for example. But since these are the Mac binaries, you can't use these signatures in Windows. You'll have to find them from the .dll with other methods, since the .dll doesn't contain debug info, like function names.
I've opened .so files in IDA before and retrieved some of the functions back from linux with names too. I'm not tech savvy so I don't know what I can do with a signature. I learned how to sigscan over at SourceMM, though.
Sorry, you need to Log In to post a reply to this thread.