Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Recommended Posts

Hello, i write code by lua but i need to use C++ because it need for my project. I searched the Internet for information about this and found only vague references or something that did not suit me for leadwerks. I learned how to call lua functions via C ++ via the Interpreter, but that's not what I need. If someone can provide a simple project (with text output to the console, for example) or a clear explanation with examples, I will be very grateful!

Link to post
Share on other sites
  • 2 weeks later...
On 1/30/2021 at 7:50 PM, reepblue said:

What is it exactly you're trying to do? You want to expose functions with glue code? 

 

Sorry for being so late, this just recently grabbed my attention.  

I want to call C++ function by lua but i don't know how to do it

Link to post
Share on other sites

I would hook you up, but the code is pretty old and I had issues with Interpreter doing so. What functions do you need to call? Unless it's math functions, it's not worth it. If it's actor assigning, please take a look at this

Link to post
Share on other sites
13 часов назад, reepblue сказал:

I would hook you up, but the code is pretty old and I had issues with Interpreter doing so. What functions do you need to call? Unless it's math functions, it's not worth it. If it's actor assigning, please take a look at this

oooh....

Okay, for example, i wrote function in App.cpp

void App::Test(lua_State* L)

{

System::Print("TEST FUNCTION");

}

in .h file i wrote in public functions this:

virtual void test(lua_State* L);

 

in test lua file i  wrote this:

function Script:Start()

   App:test()
end

but it  doesn't work. What am I missing to make this work?  It's test function, i know lua language, but I need to  rewrite part of the Lua code into C ++, but I don’t know how to call my custom C++ by lua.
That's why I started with simple functions, but I can't even just write a message to the console. 

 

 

 

 

 

 

Link to post
Share on other sites

I made these changes to make your code compile:

  • Added "#pragma once" at the top of ok.h.
  • Added "public:" in ok class.
#pragma once
#include "Leadwerks.h"

using namespace Leadwerks;

class ok
{
public:
	ok(); //lua

	void ko(); //lua

};

And I added this at the top of ok_lua.cpp:

#include "ok.h"

I did not test beyond that, but it compiles.

  • Thanks 1
Link to post
Share on other sites
39 минут назад, Optimus Josh сказал:

I made these changes to make your code compile:

  • Added "#pragma once" at the top of ok.h.
  • Added "public:" in ok class.


#pragma once
#include "Leadwerks.h"

using namespace Leadwerks;

class ok
{
public:
	ok(); //lua

	void ko(); //lua

};

And I added this at the top of ok_lua.cpp:



#include "ok.h"

I did not test beyond that, but it compiles.

820525546_.png.0118bb0675baebc95a6f2a71893efc66.png1068512633_.thumb.png.e748a02d84cde656fb2fca3021423a25.png

1742171091_.thumb.png.102c36395e302e7622c9186d07081d69.png1895923591_.thumb.png.e856f92d211c935ff95fb013141ad82c.png1461949611_.thumb.png.701f2346b20c12a6b60880888d1b915b.png

It compiled, but i got this error :(

  • Sad 1
Link to post
Share on other sites
17 часов назад, Optimus Josh сказал:

See this:

 

1834255389_.thumb.png.2c8ef71bc23e00ebb5cf9f33db78ea4b.png

THANK YOU, MR OPTIMUS JOSH, FOR YOUR HELP IN GLUE CODE! 😀

2115438366_.thumb.png.3c3f839ea8bae70aa656ed85cc6375d0.png

 628394988_.png.ed33bdaa0aab53b428311784eb007c1e.png

All ok, but when i use Debug breakpoint this doesn't work properly, or application of game closed without error or i have this error  of Visual C++

Link to post
Share on other sites
12 часов назад, Optimus Josh сказал:

Can you upload a working project I can run to test?

Okay, but it's not my project, i downloaded this in this topic and updated to newer version of leadwerks (4.6), but i fixed it. I use this example project, because i needed it to learn tolua bridge.

 

 

Shooter.zip

  • Thanks 1
Link to post
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.

×
×
  • Create New...