Sign in to follow this  
mits

Runtime error on my first Luabind program [SOLVED]

Recommended Posts

Hi, I just compiled my first Luabind program. I downloaded the compiled ibrary from [URL="http://www.nuclex.org/downloads/developers/kits/luabind-binaries-and-demo"] http://www.nuclex.org/downloads/developers/kits/luabind-binaries-and-demo[/URL] and wrote the following code:
extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}

#pragma comment(lib, "lua.msvc8.lib")
#pragma comment(lib, "luabind.msvc8.lib")


#include <luabind/luabind.hpp>
#include <iostream>
#include <string>


using namespace std;
using namespace luabind;

// The C++ functions we are going to expose in lua
void HelloWorld()
{
	cout << "Geia mas" << endl;
}


int add(int a, int b)
{
	return a+b;
}



int main()
{
	// Create a lua state
	lua_State *pL = lua_open();

	// open luanbind
	luabind::open(pL);
	
	// Register C++ functions and classes using luabing HERE 
	// Register them in globalspace
	luabind::module(pL)
	[
		luabind::def("HelloWorld", HelloWorld) 
	];


	// Load and run the script here
	// Process a file
	if(int error = luaL_dofile(pL, "test.lua") != 0)
	{
		cout << "Error with lua file" << endl;
	}


	// tidy up
	lua_close(pL);


	system("pause");
	return 0;
}
Program compiles fine but throws a runtime error when I register the HelloWorld() function. Any idea what might it be wrong? Thanks. [Edited by - mits on June 7, 2007 6:20:41 AM]

Share this post


Link to post
Share on other sites
Nevermind, I solved it by changing the Runtime Library option of the compiler to Multithreaded DLL and the project configuration to Release and it worked perfectly. Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this