LuaGlue icon indicating copy to clipboard operation
LuaGlue copied to clipboard

add helpers to determine if globals (or table fields) are specific types

Open ehrhart opened this issue 11 years ago • 3 comments

I'd like to know if it's possible to check if a global function exists before doing invokeFunction or invokeVoidFunction.

If I try to call a function that doesn't exist, the stack keeps getting filled with "`attempt to call a nil value'" Any ideas on how to prevent this?

Thanks

ehrhart avatar Sep 06 '14 18:09 ehrhart

Well, the invoke methods really should be poping the errors back off the lua stack. but I could add a globalExists or similar method.

Tomasu avatar Sep 06 '14 19:09 Tomasu

Now it wont fill the stack with junk, but you can also now check if a global exists via globalExists, it does not check its type, rather that the global is not nil. I may think about adding a couple helpers that check if its a function or table, etc, as well.

Tomasu avatar Sep 06 '14 20:09 Tomasu

Thanks a lot, works like a charm. Some helpers would be useful for sure, but globalExists helps a lot already

ehrhart avatar Sep 06 '14 21:09 ehrhart