Jump to content
  • Advertisement
Sign in to follow this  
r0swell

Howto check if a lua function exists in c#

This topic is 4371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!