lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Tue, Oct 4, 2011 at 9:54 PM, Geoff Leyland <> wrote:
On 5/10/2011, at 8:23 AM, Oskar Forsslund wrote:

> I am not using luarocks so I won't install from there.

Any reason why not?

I didn't get it to work when i started with lua and now I have a non-rocks setup

> I embed lua by linking to the lua51.lib and having the lua51.dll next to my exe
> I would like to include luatrace somehow in that setup

Shouldn't you only link to one of lua51.lib and lua51.dll?  Is this a windows thing?  I guess that part works for you so you're doing it right.

Is the end result that you're statically or dynamically linking to Lua?  In any case, I've never statically linked the hook to Lua (or anything for that matter), so I couldn't help you there.

This is(?) a dynamic linking 

> I tried compiling using the makefile in cygwin by commenting out all sections under "guessing target" that didnt create a dll (i.e. forcing it to choose the option that creates a dll)

Exactly which lines did you comment out?

13-22 and 27-42 ("guessing a platform" to "MinGW" and "else" to the third "endif")
I also changed line 25 to: LIBS=-L$(LUA_BINDIR) lua51.lib

> but I'm not sure I link it correctly to lua. I used the command -L lua51.lib

Where did you get that from?  I would have thought -llua51 (as seen in the makefile).  But right at the moment this is not your main problem.

I got an error from -llua51 so I took a bold guess and it didn't complain
> cygwin could run make install with that (ugly) hack and I got a .dll file and put that next to my exe as well.
> I also mimicked the makefile in where to put all lua files from the installation and included them in my project in a lua folder next to my exe

So you have a directory with your .exe and lua51.dll in it, and in that directory, you have a directory named "lua" and inside that there is luatrace.lua and a directory called luatrace?  Did you add "lua\?.lua" to package.path and "lua\?.dll" to package.cpath?

Presumably you are managing to run other Lua files?  Are they also in the lua folder?  Can Lua find them?

my folder structure now looks like this:
lua {
     include {
          <h-files fom lua>

> I then tried to include luatrace in my script by require and that didn't work. require couldnt find the specified file (luatrace.lua) and I'm not too surprised since there is none.

Why is there none?  Above you said you copied all the lua files to the lua folder.  Did you copy luatrace.lua or not?

I had failed and not copied that file, i have now and the require does not complain but now I get the error:

attempt to index global 'luatrace' (a nil value)
when i call type(luatrace.tron) so something still isn't right 

> TBH I'm just not sure which files to put where and what files I really need to run luatrace with embedded code.

Which is why there's a makefile and a rock.

In your case, where I doubt you'll be using -luatrace on the commandline, you need to copy luatrace.lua, the luatrace directory and the compiled hook (c_hook.dll) into somewhere on package.path or package.cpath.  c_hook.dll needs to be in a directory called luatrace.

If you mimicked the makefile, you already did that, right?

> I haven't tried setting luatrace up with my standalone lua installation

Why not?  It would be a good idea to check that works first.  I don't think your current problems are with luatrace, I think they're to do with working out how to install modules for your "embedded" Lua.

I set up luatrace with my lua installation and -luatrace works but i still get the

attempt to index global 'luatrace' (a nil value)

when i require"luatrace" and call type(luatrace.tron) (running my same script file using a visual studio command window)

then i do this

prompt>lua -luatrace test.lua
luatrace: tracing with Lua hook

<output fom test.lua> 

prompt>lua -luatrace.profile trace-out.txt
lua: trace-out.txt:1: unexpected symbol near '>'
Total time     0 nanoseconds
Times in nanoseconds
Top 20 lines by total time
File:line  Hits  Total   Self  Child | Line

Top 20 functions by self time
File:lines  Hits  Total   Self  Child | Line


the script repeats { randomly choose one string out of six and calls loadstring on it and run it } 3771 * 100 times
I should get some sort of output right? Or do I have to set up hooks in the lua code somehow?