🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Problems calling a Lua fuction with dostring (LUA 5)

Started by
4 comments, last by HexDump 19 years, 11 months ago
Hello, I have written a dumb script just to try to call a lua function from C. I use lua_dostring(). The script is just this, an empty function: function DoLogic() end. I call this from C using lua_dostring("DoLogic()"), but I allways get a violation mem error. If I do a lua_dostring("a=2") for example everthing goes well and I can get the correct value of "a" from C. The problem seems to arise with functions, anyone knows how to fix this?. Thanks in advance, HexDump.
Advertisement
How are you causing the function to be registered?
If the function does not exist Lua will complain, thus:
Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio> DoLogic()stdin:1: attempt to call global `DoLogic' (a nil value)stack traceback:        stdin:1: in main chunk        [C]: ?>


I thought the empty function might be a problem but it does not seem to be the case.
Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio> function DoLogic()>> end>> DoLogic()>


Presumably you should just have the error message at the top of the stack. When in doubt use LUA's debuging stuff.
I´m not registering the function I thougt that with dostring I din´t have to do that :/.

HexDump.
If you don't register your c function with Lua, how is lau_dostring() suposed to know about your c function to call it?

Or am I misunderstanding something?

I'm missunderstanding, you want to make a function in lua, and then call that lua function from c, right?


In that case...
How are you loading your script file?
Ok Ok, I was forgeting to register the func... newbie problem.

Thanks a lot.
HexDump.

This topic is closed to new replies.

Advertisement