Page 1 of 1

Setting up Lua on Windows using Visual C++

Posted: 16 Oct 2010, 15:54
by discodowney
Im starting Lua. Right now im just trying to get some simple scripts going, the hello worlds and basic functionality i can get through fairly quickly. But i cant find anywhere that really explains how to set up lua.

I was given this:
http://lua-users.org/wiki/TutorialDirectory

But they done explain how to set up for the Tutorials.
Also here:

http://lua-users.org/wiki/BuildingLua

But im having problems. Ive set up a simple C++ program that executes a lua script. It compiles but I get the following link errors:

1>main.obj : error LNK2019: unresolved external symbol _lua_close referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _lua_pcall referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _luaL_loadfile referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _luaL_openlibs referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _main

Im assuming its some sort of library problem. I have a book that explains how to set up. But it uses lua 5.1.3. This has .lib files that are added. 5.1.4 doesnt appear to have these .lib files. I cant find how to fix this problem. Can anyone help me out here?

Re: Setting up Lua on Windows using Visual C++

Posted: 16 Oct 2010, 18:21
by quantum
A standalone Lua interpreter is not needed for Spring scripting. Check the LuaGadgets/Gadgets, LuaRules/Gadgets or LuaUI/Widgets inside mods for examples. Here is a guide.

If you still want a standalone interpreter, you can get a precompiled one here: http://code.google.com/p/luaforwindows/

Re: Setting up Lua on Windows using Visual C++

Posted: 16 Oct 2010, 20:21
by zwzsg
What are you "starting Lua" for?

If you need Lua for Spring, to write a Spring AI for instance, then forget about Visual C++ or setting up an environnement, just type your Lua code in notepad, rename .txt to .lua and dump it in \mods\your_mod.sdd\LuaRules\Gadgets\

Re: Setting up Lua on Windows using Visual C++

Posted: 17 Oct 2010, 15:18
by discodowney
Well i want to do some test programs. Just the standard Hello Worlds, and basic functions etc, that you do when learning any new language.

Re: Setting up Lua on Windows using Visual C++

Posted: 17 Oct 2010, 18:00
by zwzsg
What about hello world as a SpringRTS widget?

Code: Select all

function widget:GetInfo()
    return {
        name = "Hello word widget",
        desc = "Says \"Hello World\" every 30s",
        author = "zwzsg",
        date = "17th October, 2010",
        license = "Public Domain",
        layer = 0,
        version = "1.0",
        enabled = true,
        handler = false,
    }
end

function widget:GameFrame(f)
    if f%900==5 then
        Spring.Echo("Hello World!")
    end
end
Save as YourSpringInstallFolder\LuaUI\Widgets\HelloWorld.lua

Re: Setting up Lua on Windows using Visual C++

Posted: 18 Oct 2010, 14:45
by discodowney
Ive got a C++ program that runs lua scripts, so im grand for now just getting used to lua basics with this. Ill have a look at widgets after. Cheers

Re: Setting up Lua on Windows using Visual C++

Posted: 18 Oct 2010, 15:49
by slogic
Here is working console interpreter.