call_function causes my program to crash

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

call_function causes my program to crash

Secretive Loon
I've successfully used call_function to call Lua functions before and didn't have a problem. I think it's because they were of global scope like:
int sum = luabind::call_function<int>( L, "add", 2, 3 );

but the one I'm trying to do now is like this, with a different scope:
luabind::call_function<void>( L, "CNPC_Nurse:Update" );

-- Here's the Lua code that I'm trying to call (in a different file from the C++, of course)
function CNPC_Nurse:Update()
Msg( "\nIn Nurse:Update" )
end

// these came earlier in the file as the above C++ code
luabind::module( L ) [
luabind::class_<CNPC_Nurse>( "CNPC_Nurse" )  
];

When I run it, it crashes the application without a message. I've narrowed it down to the call_function line causes the problem. Any idea why the "CNPC_Nurse:Update" call breaks it?

Thanks :)

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: call_function causes my program to crash

Tom McCubbin-2
I'd guess its the lua syntactic sugar of <class:method> v. <class.method> .  When you use the ':'(colon) operator in lua it infers the object to act on is the first arg passed to the method, just like 'this' in c++ is passed by the compiler.  When you call it, it would appear that you are not passing the object that Update() should act on.  When it tries, I'd bet you get a SEGV or other nasty because the stack in lua holds some random address pointing to a whose-i-jigger.

I could be completely off here...but I'm others will chime in w/ the solution.

-tom

On Sun, Aug 9, 2009 at 5:34 PM, Secretive Loon <[hidden email]> wrote:
I've successfully used call_function to call Lua functions before and didn't have a problem. I think it's because they were of global scope like:
int sum = luabind::call_function<int>( L, "add", 2, 3 );

but the one I'm trying to do now is like this, with a different scope:
luabind::call_function<void>( L, "CNPC_Nurse:Update" );

-- Here's the Lua code that I'm trying to call (in a different file from the C++, of course)
function CNPC_Nurse:Update()
Msg( "\nIn Nurse:Update" )
end

// these came earlier in the file as the above C++ code
luabind::module( L ) [
luabind::class_<CNPC_Nurse>( "CNPC_Nurse" )  
];

When I run it, it crashes the application without a message. I've narrowed it down to the call_function line causes the problem. Any idea why the "CNPC_Nurse:Update" call breaks it?

Thanks :)

------------------------------------------------------------------------------
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
[hidden email]
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
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: call_function causes my program to crash

Colm Sloan
Very interesting idea. I'll give it a go and see what happens.

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: call_function causes my program to crash

Secretive Loon
No, he tried it and it didn't work (we're on the same dev team). Perhaps it's still not implemented correctly?:
// c++ call
luabind::call_function<void>( L ), "CNPC_Nurse.Update", this );

-- Lua function
function CNPC_Nurse.Update( self )
Msg( "\nIn Nurse.Update" )
end

I checked through every Google result for call_function (13 pages) and didn't find a single one using scope the way I'm trying. Has LuaBind just not been designed with the capability?

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: call_function causes my program to crash

Iliya Trendafilov
As far as I can understand from the source
(luabind/detail/call_function.hpp, lines 349-350)
luabind::call_function<...>(lua_State*, const char*, ...) only works
with functions at global scope. call_function would have to do rather
sophisticated parsing to reach inner "scopes" - sure,
"CNPC_Nurse.Update" doesn't look very complex, but if that one works,
then "Nurses['Jessie'].Arms.Left:Update" should also work, and parsing
the latter is not trivial. But the parser to do everything for you is
there, and you can invoke it - just call

luaL_dostring(L, "CNPC_Nurse:Update()"); // luaL_dostring is a macro
from the Lua aux library, not luabind

It gets more complex if you want to get return values though. Probably
better option would be something along the lines:

luabind::object self = luabind::globals(L)["CNPC_Nurse"];
luabind::object func = self["Update"];
luabind::call_function(L, func, self);

(I haven't compiled the above code, but you get the idea)

Hope this helps,
Ilia


On Mon, Aug 10, 2009 at 3:08 PM, Secretive Loon<[hidden email]> wrote:

> No, he tried it and it didn't work (we're on the same dev team). Perhaps
> it's still not implemented correctly?:
> // c++ call
> luabind::call_function<void>( L ), "CNPC_Nurse.Update", this );
> -- Lua function
> function CNPC_Nurse.Update( self )
> Msg( "\nIn Nurse.Update" )
> end
> I checked through every Google result for call_function (13 pages) and
> didn't find a single one using scope the way I'm trying. Has LuaBind just
> not been designed with the capability?
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> 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
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: call_function causes my program to crash

Secretive Loon
The dostring method worked perfectly :D I couldn't get the object style one to work. I'll have to research that later. Nevertheless, thank you very much :) I'll get back to coding.

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

call_function with parts of string + length

Kristoffer Danielsson
Consider this:
 
char *pString = "Hello world!";
luabind::call_function<void>(L, "foo", pString);
 
For efficiency, I want to send "Hello" only, to function foo - without having to copy the string or alter the pointer array. How can this be done? It must be possible to somehow wrap the pointer with a desired length!
 
Something like this:
luabind::call_function<void>(L, "foo", luabind::parameter(pString, 5));
 
Thanks.


Använd nätet för att dela med dig av dina minnen till vem du vill.
------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user