Page 1 of 2

Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 5:43 pm
by Zorbatron
This is madness, I'm a bit new to the whole scene of large projects with C/C++, I've looked all over and no one can write it, in plain effing english how to compile Lua in Windows.

I got the source from http://www.lua.org, and am stuck. I can't open the makefile with anything, its pissing me the hell off who the shit doesn't include instructions on how to use their product?! "Here's a jetpack, you can figure out how to assemble it though".

Why should I have to spend hours of my time figuring this damn bullshit out, really I'm mad, can someone tell me :(. I have both VS 2008 and VS 2005.

Edit
I've figured out how to compile a library against lua5.1.lib, however when running it in game, it cannot find the name.

Re: Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 6:12 pm
by bartbes
There is no project file for MSVC++, just for gcc-compatible compilers. So either get one of those (called MingW on Windows) or install Lua for Windows (binaries, yay!)

Re: Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 6:20 pm
by Zorbatron
Ugh, who knows why... thanks though.

I guess I don't need to compile lua right now (I mainly wanted to look at how it worked and learn from it). I just need to know how to write a simple module, how to compile it, and how to link it to my lua scripts. I want to start intergrating C/C++ into my project.

Could you please show me how to make the simplest module you can think of and how to compile it, I cannot find out how to do this anywhere........

Edit:
Oh and btw, I can't even figure out how to install mingw, I go to their sourceforge page, and I can't open the zip, winrar says the .tar file is corrupt or damaged. Why did they make this so easy? Its way to easy, needs to be harder.

Obviously building lua is beyond me, I just want to build a module for it please help me.

Re: Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 6:28 pm
by bartbes
Assuming cpp and set up with the dlls and libs (which can be found at the LuaBinaries page)

C++:

Code: Select all

#include <lua.hpp>
#include <iostream>

int helloworld(lua_State *L)
{
    std::cout<<"Hello, world!" <<std::endl;
}

int luaopen_helloworld(lua_State *L)
{
    lua_register(L, "hello", helloworld);
}
compile that to helloworld.dll

Lua:

Code: Select all

require "helloworld"
hello()
Everything can be found here: http://www.lua.org/manual/5.1/
Every lua function has to be: int name(lua_State *L)
(where name is the name)
return value is the number of returned values, which can be 'pushed' by functions as lua_pushnumber(L, number) (as described in the manual)
The luaopen_<name> has to have the same name as the dll, it uses that in require, if you want to skip require you can use package.loadlib(<path to dll>, <function name>) to return the function to you.

Re: Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 6:31 pm
by Zorbatron
Thank you dude, you're my new best friend, I will try this and get back to you with the results.

Quick question, which download should I choose? This one (Visual C++ 2005 Compatible) lua5_1_4_Win64_dll8_lib.zip? (I'm running 64)

Re: Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 6:42 pm
by bartbes
If you want to compile to 64-bit dlls, yes, if you don't choose the x86 one.

Re: Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 6:47 pm
by Zorbatron
Alright, I've put the compiled lua dlls into my C:/lua folder, when I go to compile the code I get:

Code: Select all

1>c:\users\-------\documents\visual studio 2005\projects\dlltest\dlltest\dlltest.cpp(1) : fatal error C1083: Cannot open include file: 'lua.hpp': No such file or directory
How do I make the #include preprocessor search in my C:/lua folder?

Edit
Well, I fixed that error by copying the dlls and all the headers files in lua/includes to my project directory then added them to the project, and used #include "lua.hpp" instead of #include <lua.hpp>, however now I get this vauge error.

Code: Select all

1>testdll.obj : error LNK2019: unresolved external symbol _lua_setfield referenced in function "int __cdecl luaopen_helloworld(struct lua_State *)" (?luaopen_helloworld@@YAHPAUlua_State@@@Z)
1>testdll.obj : error LNK2019: unresolved external symbol _lua_pushcclosure referenced in function "int __cdecl luaopen_helloworld(struct lua_State *)" (?luaopen_helloworld@@YAHPAUlua_State@@@Z)

Re: Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 7:07 pm
by bartbes
It's been a while since I've done that, all I know is that you need to open your project settings (or global settings if you want this for every project) there is a tab called "Libraries" (or similar, it's been a while) and "Includes", add the path in both of those.

Re: Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 7:23 pm
by Zorbatron
Alright thanks, set that up, still getting those two errors though, about an unresolved external link? I'm Building Solution (F7), is this the wrong way?

Re: Can someone tell me how to build Lua on Windows?

Posted: Mon Jul 13, 2009 7:24 pm
by bartbes
That means it can't find the libraries, that needs to be setup like I posted.