Rocko Posted January 20, 2021 Share Posted January 20, 2021 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! Quote Link to comment Share on other sites More sharing options...
reepblue Posted January 30, 2021 Share Posted January 30, 2021 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. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Rocko Posted February 4, 2021 Author Share Posted February 4, 2021 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 Quote Link to comment Share on other sites More sharing options...
Josh Posted February 5, 2021 Share Posted February 5, 2021 tolua++ is the library we use. It will do what you need. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rocko Posted February 6, 2021 Author Share Posted February 6, 2021 20 часов назад, Optimus Josh сказал: tolua++ is the library we use. It will do what you need. How exactly can i use it? Quote Link to comment Share on other sites More sharing options...
Yue Posted February 6, 2021 Share Posted February 6, 2021 5 hours ago, Rocko said: How exactly can i use it? toLua home page (puc-rio.br) Quote Link to comment Share on other sites More sharing options...
reepblue Posted February 7, 2021 Share Posted February 7, 2021 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. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Rocko Posted February 7, 2021 Author Share Posted February 7, 2021 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. Quote Link to comment Share on other sites More sharing options...
Rocko Posted February 7, 2021 Author Share Posted February 7, 2021 19 часов назад, Dark Yue сказал: toLua home page (puc-rio.br) i readed it, but I didn't understand anything otherwise I wouldn't write there about this Quote Link to comment Share on other sites More sharing options...
Josh Posted February 7, 2021 Share Posted February 7, 2021 This describes usage: https://www8.cs.umu.se/kurser/TDBD12/VT04/lab/lua/tolua++.html 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rocko Posted February 7, 2021 Author Share Posted February 7, 2021 1 час назад, Optimus Josh сказал: This describes usage: https://www8.cs.umu.se/kurser/TDBD12/VT04/lab/lua/tolua++.html I have many errors Source.zip Quote Link to comment Share on other sites More sharing options...
Josh Posted February 7, 2021 Share Posted February 7, 2021 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. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rocko Posted February 7, 2021 Author Share Posted February 7, 2021 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. It compiled, but i got this error 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted February 8, 2021 Share Posted February 8, 2021 See this: 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rocko Posted February 8, 2021 Author Share Posted February 8, 2021 16 часов назад, Optimus Josh сказал: See this: THANK YOU, MR OPTIMUS JOSH, FOR YOUR HELP IN GLUE CODE! ? Quote Link to comment Share on other sites More sharing options...
Rocko Posted February 8, 2021 Author Share Posted February 8, 2021 17 часов назад, Optimus Josh сказал: See this: THANK YOU, MR OPTIMUS JOSH, FOR YOUR HELP IN GLUE CODE! ? 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++ Quote Link to comment Share on other sites More sharing options...
Josh Posted February 10, 2021 Share Posted February 10, 2021 Can you upload a working project I can run to test? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rocko Posted February 10, 2021 Author Share Posted February 10, 2021 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 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.