Re: Assert thrown calling basic C++ function

"Brian Hughes" <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <000201ca1016$66063c10$3212b430$@com>
Hi Daniel,

It asserts when Lua attempts to call the function in the script (it's only a
one line script of calling the function).

I have the luabind header included in my project for compiling, and I'm
linking to a pre-built static library that I made.

Here are the relevant parts of the code (due to the project's size, I can't
give everything from A-Z but I don't believe any other parts of code such as
the rendering pipeline would cause an issue as it doesn't even touch this
stuff).

Loading Lua/Luabind:
int ScriptingManager::InitLua()
{
	// Open Lua
	m_luaState = lua_open();

	// Load basic libraries
	luaL_openlibs(m_luaState);

	// Open LuaBind
	luabind::open(m_luaState);

	if(m_luaState == NULL)
		return -1;
	else
		return 0; // Success!
}

Defining of function in code, run once:
	luabind::module(GetState())
		[
			luabind::def("sayhello", &sayhello)
		];

Sayhello function, defined in the global namespace:
void sayhello(void)
{
	return;
}

How I'm running my script:
void ScriptingManager::Run(const char* script)
{
	int ret = luaL_dofile(m_luaState, script);
	if(ret != 0)
	{
		if(!lua_isstring(m_luaState, lua_gettop(m_luaState)))
		{
			return;
			
		}

		std::string errorString = lua_tostring(m_luaState,
lua_gettop(m_luaState));
		lua_pop(m_luaState, 1);
	}
	
}

Test.lua (script I'm running) is simply:
Sayhello()

luaL_dofile returns 1

errorString contains the value of: 
"void 
ð­ºsayhello()"

Without quotations however.

Thanks for replying!
~Brian Hughes

> -----Original Message-----
> From: Daniel Wallin [mailto:[email protected]]
> Sent: Wednesday, July 29, 2009 1:04 AM
> To: [email protected]
> Subject: Re: [luabind] Assert thrown calling basic C++ function
> 
> On 7/29/09 1:11 AM, Brian Hughes wrote:
> > Hello everyone,
> >
> > I’m a new user to both Lua and LuaBind, so I’m hoping I’m just making
> > a simple mistake in my program! I’m implanting Lua/LuaBind into an
> > existing codebase.
> >
> >
> > I’m starting by doing a very basic test of calling a global C++
> > function from within a lua script. Nothing fancy, however it is
> > throwing an assert trying to call the function.
> >
> >
> > I do all of the setup (open lua state, open lua libs, open luabind),
> > then define my function as follows:
> >
> >       luabind::module(gScriptManager->GetState())
> >       [
> >             luabind::def("sayhello", &sayhello)
> >       ];
> >
> >
> >
> > Where sayhello is quite basic:
> >
> >
> > void sayhello(void)
> > {
> >       return;
> > }
> >
> > However, when I try to run a script that only has: sayhello()  in it,
> > luaL_dofile returns a value of 1 (some error, which is supposedly a
> > YIELD error?), and when I use Decoda to debug Lua, it is throwing an
> > assert when it tries to call the function.
> 
> Where does it assert?
> 
> > I’m using Lua 5.1.4 with LuaBind 0.8.1 on MS Visual Studio 2005.
> 
> How are you building luabind? It can obviously handle this basic usage, so
it
> doesn't seem very likely it's a bug in the library. Can you supply the
complete
> failing code (C++ and Lua) please?
> 
> --
> Daniel Wallin
> BoostPro Computing
> http://www.boostpro.com
> 
>
----------------------------------------------------------------------------
--
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
> trial. Simplify your report design, integration and deployment - and focus
on
> what you do best, core application coding. Discover what's new with
Crystal
> Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.