🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

problems embedding lua

Started by
40 comments, last by nekoflux 20 years, 4 months ago
Hi: I''ve been having trouble getting the libraries for lua integrated with my code. A little background information: My development environment is msvc++ version 6. I am trying to use lua v4.0.2 (yes, Im aware its a slightly older build, that is an intentional decision to avoid gpl licensing restrictions that lua 5 incurs) I have several questions I suppose: 1) where are the static libs? I''v visited lua.org and have been unable to procure the procompiled library for windows, or for that matter a msvc project that I can build from source with. 2) All the examples I''ve seen that embed lua involve a main() function....while this is fine for small test examples I may create in expirimenting with lua, this will not suffice in my codebase. Are there any peculiar things I need to do in order to embed lua in a file containing a class definition without any main() function declaration? So many questions, but those are the 2 major ones I can think of at the moment. Does anyone have an ultra simple example project in msvc that is a minimal example of how to embed lua in c++ that will compile when I unarchive it? I''m not a guru, but i''m fairly competent with c/c++, etc any help would be appreciated, thank you in advance!!
nekoflux
Advertisement
You need to compile the library yourself. Just create a new static library project, put all the lua files in (as I recall there is a list in one of the readme files for which files to include).
I've tried creating a static project but then there isnt much documentation on what files go where....Is there just a flat list of files I dump in the root directory of the project folder that gets created?

the directory of the archive is a bit confusing:
lua.tar.gz  |  _---./src/  |      |----lib/  |      |     |  |      |    more files...  |      |  |      |----lua/  |      |     |  |      |    more files  |      |  |      |----luac/  |      |     |   |      |    more files  |      |    |      |  |      |----even more files here   |---./include/         |--lua.h         |--luax.lib         |--lualib.h  


Iunerstand that the folders src/lua and src/luac arent needed if I just want my program to use the lib at runtime to interpret lua scripts, but why is there a src/lib directory?
do I only need to build the files in src/ and ignore src/lib?

sorry for the verboseness of my response...



[edited by - nekoflux on February 5, 2004 2:16:24 AM]
nekoflux
quote: Original post by nekoflux
My development environment is msvc++ version 6. I am trying to use lua v4.0.2 (yes, Im aware its a slightly older build, that is an intentional decision to avoid gpl licensing restrictions that lua 5 incurs)


Having used LUA in several projects, I''d like to correct your issue here.

LUA 5.0''s primary license is the very liberal MIT license.

"
Lua 5.0 license
Copyright © 2003 Tecgraf, PUC-Rio.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"

http://www.lua.org/copyright.html

------------------------------ BOOMZAPTry our latest game, Jewels of Cleopatra
Thanks for clearing that up dude.

Heres my next issue

I have downloaded the source for lua 5.0. I got the lib to compile by doing the following:
1) created a new win32 static libarary project
2) copied all files in the src/ and lib/ directories into the main project directory
3) clicked "build all"
4) it spits out lua.lib in my debug/ directory

ok, this is fine, as expected.
I create a new win32 console application, copy the newly created lua library to the new project, along with all the header files. I then open up the cpp file containing main, and
it looks like this when i''m done:
extern "C"{#include "lua.h"#include "lualib.h"}int main(int argc, char* argv[]){	lua_State* luaVM = lua_open();	if (NULL == luaVM)   {      printf("Error Initializing lua\n");      return -1;   }   char* strLuaInput = "a = 1 + 1;\n";    loadstring(luaVM, strLuaInput);      lua_close( luaVM );   return 0;} 


everything compiles fine, except for the the loadstring() line, which is flagged in the compiler with the following error:
error C2065: ''loadstring'' : undeclared identifier

its seeing the other calls to lua and allowing me to compile and link the program (if I comment the line out it works fine)
why is this choking? any thoughts?

thanks a lot!!
nekoflux
The files in the base source directory src/ are for building the static library, liblua . The files in the source directory src/lib/ are for building the base library liblualib , which implements the basic Lua libraries to provide file functions, IO, math, etc... to Lua scripts. The files in src/lua/ are the source files for building lua , the command-line interpreter. The files in src/luac/ are for building luac , which compiles script files into bytecode.

I don't have any familiarity with whatever bass-ackward way MSVC does things, but the Lua source package should have standard Makefiles in each directory, which you can take a look at to see which obj/.c files you need to include for which components, so you can construct whatever wierd things MSVC requires. You could also go ahead and download the pre-compiled version 5 binary for Windows, as I believe it includes MSVC project files that you could hack for your own nefarious purposes.

They have pre-compiled versions for the latest release here. The Wiki policy is to only provide pre-compiled binaries for the latest version, though, so that means 5. But 5's project files can be hacked. Oh, yes, precioussss, they can be hacked, indeed. (BTW: As of this writing, it looks like the SourceForge page where the binaries are is down for scheduled downtime, so you may need to wait a bit.)

I don't really understand what kind of GPL licensing restrictions you think Lua 5 has. Lua 5 is under the MIT license, which is compatible with the GPL, but which does not force you to release your own source code. If you GPL your code, the Lua license still applies to Lua; that is,the GPL doesn't affect it. If you don't GPL, but elect to keep it closed source, the MIT license is perfectly, sanguinely fine with that.

As far as having the main() function-- of course it's necessary. All C/C++ executables need it. (I understand Windows cleverly (foolishly? ) disguises it, however; but it's still main(), even if by a different name). However, it is not necessary to only use Lua in the source file with main() in it (if I am reading you correctly). Lua is just a bunch of functions; they can be called from any source file, as long as the Lua headers are included. Those examples are all single-sourcefile examples because it is not necessary to have 50 files for an example; not because of any limitations Lua imposes.


EDIT: Heh. Took too long.

Golem

Blender--The Gimp--Python--Lua--SDL
Nethack--Crawl--ADOM--Angband--Dungeondweller

[edited by - VertexNormal on February 5, 2004 2:44:20 AM]
I believe loadstring() is only in Lua 5.0

Golem

Blender--The Gimp--Python--Lua--SDL
Nethack--Crawl--ADOM--Angband--Dungeondweller
thanks man, I appreciate you clearing up several of those points.

I did actually go retrieve the source for lua 5.0 and built it, but its still complaing. I tried both doString() (which is deprected in 5.0) and loadstring to no avail

I'm still having trouble getting my program to compile with the loadstring line, it still chokes (plz see above post)

thanks again guys!!!

[edited by - nekoflux on February 5, 2004 2:51:56 AM]
nekoflux
Try using the function int lua_dostring (lua_State *L, const char *string); instead of loadstring(). I believe loadstring() was introduced only in 5.

EDIT: Ack, nevermind. I read your earlier post to mean that you copied the Lua 4.0 files into the 5.0 project directories. Not sure why it can't find loadstring() if it's a 5.0 build...

Golem

Blender--The Gimp--Python--Lua--SDL
Nethack--Crawl--ADOM--Angband--Dungeondweller

[edited by - VertexNormal on February 5, 2004 2:55:42 AM]
I''m using the lua 5.0 lib now and I tried both doString() (which is deprected in 5.0) and loadstring to no avail
nekoflux

This topic is closed to new replies.

Advertisement