# Embedded Lua "dofile" path problem

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

## 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 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.

##### 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 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 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!

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632940
• Total Posts
3009328
• ### Who's Online (See full list)

There are no registered users currently online

×