Debriefing > Questions, Help, & How To's
Read Me
Slinky:
Just a note- you may have to add support for the 'require' method itself. I tried to implement this immediately, figuring that it just wouldn't be able to find my file but instead got this:
Executing listen server config file
[LUA-ERR] Error running function "eliminatio": [string "eliminatio"]:1: attempt to call global 'require' (a nil value)
So it looks like require isn't implemented in 3.1's lua libraries.
killermonkey:
Shit, looks like you'll have to wait for BETA 4 in order to implement your module system properly. I had to add the "Package Library" to the LUA environment in order to get the 'require' function.
By the way, the proper way to set the path for "require" and not have an environment variable for it is to set:
package.path = "C:/Program Files/Steam/steamapps/SourceMods/gesource_svn/scripts/gameplay/?.lua";
Where package is the global table that comes from the "Package Library."
So this is working wonderfully in Beta 4 now. Sorry that it won't work out for B3.1.4.
--- Code: ---
(C++)
// Define our path
char fullpath[ 512 ] = { 0 };
filesystem->RelativePathToFullPath( "scripts/gameplay", "MOD", fullpath, sizeof(fullpath) );
Q_strncat( fullpath, "\\?.lua", sizeof(fullpath) );
lua_getglobal(GetLua(), "package");
if (LUA_TTABLE != lua_type(GetLua(), 1))
return;
lua_pushlstring(GetLua(), fullpath, Q_strlen(fullpath) );
lua_setfield(GetLua(), 1, "path"); /* package.path = fullpath */
(LUA)
testfunc.lua
function TestFunc()
ClientPrintAll(HUD_PRINTTALK, "TEST FUNC!");
end
deathmatch.lua
require( "testfunc" );
function PlayerKilled( victim, killer )
TestFunc();
end
--- End code ---
Slinky:
Cool, good to hear this will be fixed in 4. Thanks so much!
Mark [lodle]:
Monkey why dont you checkout 3.1.4 and add this in, send the server dll to slinky so slinky can make sure it works 100% before beta 4. :P
killermonkey:
For someone who doesn't have a lot of time you sure know how to make other people do a lot of work, Mark. :-P
Yah, I'll do that for the poor sap, I'll post it up here for anyone who wants to try, **THIS WILL BE BETA 3.1.4.1 NOT BETA 4 IN ANY WAY**
EDIT:
Beta 3.1.4.1 (added LUA support for the "require" module)
http://www.divshare.com/download/8081271-067
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version