Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google Log In with Steam Sign In
  • Create Account
Photo

how to change where the lua is located?

- - - - - lua code location

  • Please log in to reply
21 replies to this topic

#1
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

Hey I am working on my mod modernfront, based on ETpub 1.0.0

And I wondered how to make the lua api look for a folder inside the modfolder called luascripts as in ETnam mod??

What do I change to make it work?



#2
OFFLINE   Zelly

Zelly

    Regular Member

  • Coders
  • PipPipPip
  • 141 posts
73
Getting Better

package.path and package.cpath

local mod_path = string.gsub( et.trap_Cvar_Get("fs_basepath"),"\\","/") .. "/" .. et.trap_Cvar_Get("fs_game") .. "/"
package.path = package.path .. ";" .. mod_path .. "luascripts/?.lua"

That is what it looks like in lua. I think this is what you want. (Changing it in in the c api, may be different though im not sure)



#3
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

package.path and package.cpath

local mod_path = string.gsub( et.trap_Cvar_Get("fs_basepath"),"\\","/") .. "/" .. et.trap_Cvar_Get("fs_game") .. "/"
package.path = package.path .. ";" .. mod_path .. "luascripts/?.lua"

That is what it looks like in lua. I think this is what you want. (Changing it in in the c api, may be different though im not sure)

probably but I belive there is more to it, so I will wait for a coder to answear me .. I am no coder so I need to know both wich file to change and what to change



#4
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

ok, I see I wont get more help here.. Thx for your help @zelly



#5
OFFLINE   gaoesa

gaoesa

    Advanced Member

  • Management
  • PipPipPipPip
  • 4391 posts
341
Will become famous
  • LocationFinland

In ETPub based Lua modules, the scripts are read in the

qboolean G_LuaInit()

function at g_lua.c. I think that is the place to make the modifications. I would suggest adding a cvar for the directory, similar to g_mapConfigs and g_mapScriptDirectory cvars.



#6
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

thx @gaoesa :) , no I actually want to lock it to that directory.. would be much easier for server admins



#7
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

I did this in g_lua.c:

// set LUA_PATH and LUA_CPATH
	trap_Cvar_VariableStringBuffer( "fs_basepath", basepath, sizeof( basepath ) );
	trap_Cvar_VariableStringBuffer( "fs_homepath", homepath, sizeof( homepath ) );
	trap_Cvar_VariableStringBuffer( "fs_game", gamepath, sizeof( gamepath ) );

	luaPath = va( "%s%s%s%s?.lua;%s%s%s%slualibs%s/luascripts/?.lua",
		homepath, LUA_DIRSEP, gamepath, LUA_DIRSEP,
		homepath, LUA_DIRSEP, gamepath, LUA_DIRSEP, LUA_DIRSEP );

	luaCPath = va( "%s%s%s%slualibs%s?.%s",
		homepath, LUA_DIRSEP, gamepath, LUA_DIRSEP, LUA_DIRSEP, EXTENSION );

	// add fs_basepath if different from fs_homepath
	if( Q_stricmp( basepath, homepath ) ) {
		luaPath = va( "%s%s%s%s?.lua;%s%s%s%slualibs%s/luascripts/?.lua;%s",
			basepath, LUA_DIRSEP, gamepath, LUA_DIRSEP,
			basepath, LUA_DIRSEP, gamepath, LUA_DIRSEP, LUA_DIRSEP, luaPath );

		luaCPath = va( "%s%s%s%slualibs%s?.%s;%s",
			basepath, LUA_DIRSEP, gamepath, LUA_DIRSEP, LUA_DIRSEP, EXTENSION,
			luaCPath );
	}

but it still doesnt find the scripts

 

just say:

lua_api:no scripts loaded

 

argh, driving me nuts!!



#8
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

ok, it still loads it from modfolder.. so it must be something else



#9
OFFLINE   Dragonji

Dragonji

    Advanced Member

  • Members
  • PipPipPipPip
  • 514 posts
142
On the road to fame
  • LocationPoland

Just have a look at how it's done in g_mapConfigs and g_mapScriptDirectory cases  :)


Edited by Dragonji, 18 February 2015 - 07:59 PM.


#10
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

problem solved by Jenkins, now it even autoloads lua from luascripts folder :D

 

cant be easier than that

just need to find out the limit of luas



#11
OFFLINE   Dragonji

Dragonji

    Advanced Member

  • Members
  • PipPipPipPip
  • 514 posts
142
On the road to fame
  • LocationPoland

Does it load everything what's placed there? I don't think it's wanted behaviour.



#12
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

Does it load everything what's placed there? I don't think it's wanted behaviour.

why not, its very easy for an serveradmin then?!



#13
OFFLINE   Dragonji

Dragonji

    Advanced Member

  • Members
  • PipPipPipPip
  • 514 posts
142
On the road to fame
  • LocationPoland

I personally would like to have control over loaded Luas so I can only load mods I really want, not all mods from the specific directory. It works this way in every single ET modification.



#14
OFFLINE   ETsneak

ETsneak

    Regular Member

  • Members
  • PipPipPip
  • 106 posts
19
On a distinguished road

Either way, would be nice to have a lua folder to have the lua modules all in a folder instead of loose in the mod directory



#15
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

I personally would like to have control over loaded Luas so I can only load mods I really want, not all mods from the specific directory. It works this way in every single ET modification.

I know, but why have lua mods in that folder if you not gonna use them^^



#16
OFFLINE   Dragonji

Dragonji

    Advanced Member

  • Members
  • PipPipPipPip
  • 514 posts
142
On the road to fame
  • LocationPoland

Hmm, testing purposes?



#17
OFFLINE   Purple

Purple

    Advanced Member

  • Banned
  • PipPipPipPip
  • 157 posts
56
Getting Better

Hmm, testing purposes?

unsafe to start, and with mods like lesm and upcoming ones this could be a huge problem, just for the simple fact its loading everysingle lua file over and over and we don't want this :)



#18
OFFLINE   Purple

Purple

    Advanced Member

  • Banned
  • PipPipPipPip
  • 157 posts
56
Getting Better

probably but I belive there is more to it, so I will wait for a coder to answear me .. I am no coder so I need to know both wich file to change and what to change

just because he doesn't have the coder tag doesn't mean he can't code :D



#19
OFFLINE   Zelly

Zelly

    Regular Member

  • Coders
  • PipPipPip
  • 141 posts
73
Getting Better

To be fair, he was asking about the C API part which I don't know about :D

 

But yes, if it loads all lua files recursively that would be bad for projects like myn.



#20
OFFLINE   twt_thunder

twt_thunder

    Regular Member

  • Members
  • PipPipPip
  • 68 posts
13
A step in the right direction
  • LocationNorway

unsafe to start, and with mods like lesm and upcoming ones this could be a huge problem, just for the simple fact its loading everysingle lua file over and over and we don't want this :)

why is it unsafe to start?

 

To be fair, he was asking about the C API part which I don't know about :D

 

But yes, if it loads all lua files recursively that would be bad for projects like myn.

I didnt think this far, but I am not sure your project is needed on this mod yet :)

 

just because he doesn't have the coder tag doesn't mean he can't code :D

 

I am absolutely no coder, but even I start to find my way around on smaller things, first code I did as actually worked was to change path on the binocs so it loads the new one...lol







Also tagged with one or more of these keywords: lua, code, location

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users