PROBLEM TO CALL EXTERNAL FUNCTION

All about writing scripts for Celestia in Lua and the .cel system
Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 45
With us: 17 years
Location: Milan, Italy

PROBLEM TO CALL EXTERNAL FUNCTION

Post #1by rinoa79 » 17.09.2008, 20:06

Hi,
I have created my personal function and I put it into Celestia directory but when I try to call it by a script Celestia tell me that It doesn't exist.

P.S.:I wrote at the beginning of the script

Code: Select all

celestia:requestsystemaccess()
wait(0.0)


Can somebody tell me where is my mistake?
Thx in advance!

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 3 months
Location: NY, USA

Re: PROBLEM TO CALL EXTERNAL FUNCTION

Post #2by selden » 17.09.2008, 21:23

Vincent wrote:The default directory that Lua uses
to look for Lua files is the directory of the executable file,
i.e., celestia.exe.

One can define a different path in the celx script using:
package.path = "mypath/?.lua;"

So just add the following line at the beginning of your script
to tell Lua to look for Lua files in the directory of your script:
package.path = celestia:getscriptpath().."/../?.lua;"
Selden

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 45
With us: 17 years
Location: Milan, Italy

Re: PROBLEM TO CALL EXTERNAL FUNCTION

Post #3by rinoa79 » 17.09.2008, 23:42

selden wrote:
Vincent wrote:The default directory that Lua uses
to look for Lua files is the directory of the executable file,
i.e., celestia.exe.

One can define a different path in the celx script using:
package.path = "mypath/?.lua;"

So just add the following line at the beginning of your script
to tell Lua to look for Lua files in the directory of your script:
package.path = celestia:getscriptpath().."/../?.lua;"

Sorry if you still disturbing, but I can not make it work!
Celestia tell me that there is some problem with requestsystemaccess().
I added at the beginning of my script:

Code: Select all

package.path = celestia:getscriptpath("C:Program\Celestia\myfunction.lua;")

Is it right if I write like that?
Sorry both are a little raw ... :oops:
thanks for all your help!

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Re: PROBLEM TO CALL EXTERNAL FUNCTION

Post #4by Vincent » 18.09.2008, 15:46

rinoa79 wrote:I have created my personal function and I put it into Celestia directory but when I try to call it by a script Celestia tell me that It doesn't exist.
If the Lua file that contains your function is placed in the Celestia base folder, you shouldn't need to
define a different path using package.path. Lua just looks by default in the Celestia base directory
to find lua required files. So the problem must comes from somewhere else -- I would bet on a wrong require call.

Also, it would be quite helpful if you could provide your celx and lua files for testing.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 45
With us: 17 years
Location: Milan, Italy

Re: PROBLEM TO CALL EXTERNAL FUNCTION

Post #5by rinoa79 » 22.09.2008, 17:40

I solved my problem by putting the beginning of the file after requiresystemaccess

Code: Select all

dofile ("filename")


Thanks for your help!


Return to “Scripting”