Skip to main content
gamedev.net
🔒 Locked

lua_register not working

Started by Kylotan 4 replies 2.8k views
Original Post
Kylotan
Kylotan
This is strange... I have a function that I register with Lua using lua_register (specifically: lua_register(L, "GetPCCalled", Lua_GetPCCalled); ), yet when I try to call it in a script, it says "../testlua.lua:1: attempt to call global `GetPCCalled' (a nil value)". Some of my other functions bind just fine so I've no idea what the problem is. When I iterate through the table of globals it's just not in there. Anybody got any clues at what I could look at to fix this?
Endurion
Endurion
Hm, probably just a little typo somewhere: Check the lua_State pointer, if the one you register it in and the one you call the script on is the same.

Check the global table right after registering the funtion, if it's there.

Other than that, step into the register call of GetPCCalled, you might find the cause reading the comments inside Lua.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Sneftel
Sneftel
table.foreach(_G, print) is your friend here. It usually shows me exactly what I'm doing wrong WRT function registration.
Kylotan
Kylotan
Guys, I did say "When I iterate through the table of globals it's just not in there." so I already know that. As for the lua_State pointer, it is exactly the same as the one used on the next line for a function that binds perfectly.

I'll try and step into the register call this evening, though that's possibly going to be a problem as (a) lua_register is a macro which might not play well with step by step debugging, and (b) I'll need to work out how to do this under gdb. :)

As an addendum, to make matters worse, in 5.1 they seem to have completely removed lua_register, added in luaL_register which does something completely different, and failed to note this in the 'Changes in the API' section. This isn't the first time they've done this either, having done something very similar with lua_loadstring (or whatever it was called) between versions 4 and 5. Grr!

[Edited by - Kylotan on January 23, 2006 7:42:27 AM]
Squirm
Squirm
The macro expands into 3 separate function calls. I'd suggest expanding it by hand if the debugger won't help and verifying that each one works as you call it . . .
Kylotan
Kylotan
I think on the version of Lua I'm using, it expands into 2 function calls, neither of which have any sort of return value. Either way, it seems to have been some sort of build problem, possibly caused by my inept use of Scons to assemble everything, because it's working ok now. Cheers for the suggestions though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.