Jump to content

Integrating LUA and C++ in the same project


martyj
 Share

Recommended Posts

I have been trying to integrate LUA and C++ in the same project and I keep running into roadblock that require more of my code to be re-written in C++.

 

I was wondering if anyone has managed to get C++ and Lua to be able to do things like draw to the screen.

 

From what I can see, everything is either written in all C++ or everything is all written in Lua with C++ just setting up an interpreter.

 

Does anyone have any experience/examples/documentation on the Interpreter class?

Link to comment
Share on other sites

Does anyone have any experience/examples/documentation on the Interpreter class?

 

What would you like to know?

 

Here is an example of pushing data from C++ to lua;

 

http://www.leadwerks.com/werkspace/blog/138/entry-1288-pushing-complex-lua-tables-from-c/

 

If your up to digging through C++ code there is some examples of going in both directions here https://bitbucket.org/guppy42/cppandluatest (be ware this project is semi-retired)

 

Finally the c++ source code for the lua version is in the source folder of any lua project you create - you can take that and replace your app.h/c++ of your c++ project and it will work exactly like the lua project - except for any changes you make

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

the way you get your context in LUA does not change when you use a C++ project.

 

You should be able to use http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/contextgetcurrent-r632 to get your current context and then just draw on it like normal.

 

 

Edit:

And actually you probably don't even need the above since the

Script:PostRender(context) function already provides you with the context.

Link to comment
Share on other sites

Guppy, you're my hero.

 

Any idea how to pass a C++ context to Lua?

 

I'd like to be able to draw in either C++ or Lua.

 

Same with window.

 

As already pointed You dont really want to pass those as getCurrent work in both cases, also passing anything other than simple types is error prone.

 

Window:GetCurrent()

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/window/windowgetcurrent-r628

 

Context:GetCurrent()

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/context/contextgetcurrent-r632

 

The bitbucket link has examples of passing data in both directions as well as calling lua functions from C++ and vice versa, but as I said it will require some digging as it's a more or less complete gui

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...