• Advertisement
Sign in to follow this  

Embedded Lua "dofile" path problem

This topic is 2346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,
I have a small problem:

I have Lua embedded in C++. I load and execute my initialization script just fine. At the end of it is dofile command that should execute another script containing loading of my game assets. However, no matter how I change the path of the file, it will not execute.

Should the path be relative to my executable or to the script that is calling the dofile?

Share this post


Link to post
Share on other sites
Advertisement
dofile() wants the script to be relative to the execution directory. However, if you use require, you can make use of the LUA_PATH global variable to specify directories to search. Using require is similar to dofile, but with the added bonus that subsequent calls to require for a particular file won't trigger a reload/re-parse of the file.

Share this post


Link to post
Share on other sites

dofile() wants the script to be relative to the execution directory. However, if you use require, you can make use of the LUA_PATH global variable to specify directories to search. Using require is similar to dofile, but with the added bonus that subsequent calls to require for a particular file won't trigger a reload/re-parse of the file.


Thank you, that clears up the things and fixed my problem.

I have another question:

In my engine, I load all the scripts into the memory, so I can call doLine and execute scripts from c++. The function to retreive the script returns char*. Is there way to execute this array of characters from within LUA, aka doLine and pass in the char* pointer?

Share this post


Link to post
Share on other sites
The function loadstring can be called with a string, and will return a compiled Lua chunk as an anonymous function:


s="for i=1,10,1 do print(i) end"
chunk=loadstring(s)
chunk()
1
2
3
4
5
6
7
8
9
10

Share this post


Link to post
Share on other sites

The function loadstring can be called with a string, and will return a compiled Lua chunk as an anonymous function:


s="for i=1,10,1 do print(i) end"
chunk=loadstring(s)
chunk()
1
2
3
4
5
6
7
8
9
10



Awesome, thank you!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement