• Advertisement
Sign in to follow this  

Runtime error on my first Luabind program [SOLVED]

This topic is 3915 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I just compiled my first Luabind program. I downloaded the compiled ibrary from http://www.nuclex.org/downloads/developers/kits/luabind-binaries-and-demo 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
Advertisement
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
Sign in to follow this  

  • Advertisement