Re: Call a lua function and pass a C++ Class object
James Porter <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Beric Holt wrote:
> I'm getting an exception in the proxy_function_caller->Ret operator code (on line 157 of call_function.hpp of luabind-0.8.1). The exception description is "luabind::cast_failed at memory location 0x0017ebd0."
>
> It looks like it's trying to check the return type of the function that I'm trying to call. Because the function is declared in Lua script, and not explicitly declared with a luabind def statement, it doesn't know the full function signature.
It's probably trying to cast to an integer, but the thing you're
returning isn't an integer (this applies to returning nothing as well).
Make sure all your control paths return an object of the expected type
(an int in this case). Note that this does *not* apply if you don't use
the return value of the function. That is:
----- Lua -----
function foo(arg)
arg:do_something()
-- Note the lack of a return statement.
-- The same thing would happen with this, too:
-- return "Hello, C++!"
end
----- C++ -----
luabind::call_function<int>(state,"foo",arg); // succeeds
int i = luabind::call_function<int>(state,"foo",arg); // FAILS
----- End code -----
Specifically, what happens is that call_function creates an instance of
proxy_function_caller, which has a conversion operator for int (or
whatever return type you specified). When that conversion operator is
called, it will attempt to convert the return value of the Lua function
to your requested type, and will throw luabind::cast_failed if it can't.
- Jim
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com