Sign in to follow this  
r0swell

Howto check if a lua function exists in c#

Recommended Posts

The topic schould say enough, I'm trying to make c# to check if a lua function exists without calling it, Any idee's? Found a priv post but didnt explained how to do it in c# Regards

Share this post


Link to post
Share on other sites
That depends on how you're interfacing with Lua (i.e. LuaInterface versus direct C interop).

It's been a while since I used LuaInterface, but luaState["function_name"] should return null if the function isn't defined or a LuaFunction if it is.

If you're using the C API through P/Invoke then use lua_getfield(luaState, LUA_GLOBALSINDEX, "function_name") and see if the value at -1 on the stack is nil (not defined) or a function (defined).

Share this post


Link to post
Share on other sites
I am using LuaInterface.

ive tryed the luaState but gived an error.

Also u know of any turtorials about using lua trough direct C interop?

I'm fairly new to c# but i like to give it a shot =)

Thnx for the quik respondse

Share this post


Link to post
Share on other sites
Quote:
Original post by r0swell
Also u know of any turtorials about using lua trough direct C interop?
Using Lua through direct P/Invoke bindings is exactly the same as using the normal C API. This means that you can use pretty much any C++/C tutorial on Lua, and port it almost directly to C#.

The Tao Framework currently provides bindings to Lua 5.1 (Tao.Lua). Unfortunately though, there hasn't been a binary release for it so you'd have to get it through the SVN as well as download the Lua Binaries yourself. Tao.Lua comes with two example programs that work in both .NET and Mono.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this