Guppy Posted October 1, 2014 Share Posted October 1, 2014 In an effort to keep thing simple I decided to try and move my entire game loop to lua rather than c++. Unfortunately it seems that this file isn't called from the c++ version - I get why as it would duplicate functionality. But even so I wanted to do it, the plan was; Enity* app; bool App::Start() { /* set up anything that lua migth need */ app = Pivot:Create(); app->CallFunction('Start'); //Attach 'scripts/App.lua' to app here /*extra c++ stuff that lua dont care about here*/ } bool App::Loop() { if ( !app->CallFunction('Loop') ) { return false; } } But as far as I can see there is no possible way of attaching that script? I may be braving uncharted waters here, but I think it should be possible to use the C++ version as "lua version with c++ stuff added in" 1 Quote 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 More sharing options...
nick.ace Posted October 2, 2014 Share Posted October 2, 2014 One up on this as well. I want to know if this is possible, because I love Lua, but I also want to possibly access C++ libraries and commands in the future. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 2, 2014 Share Posted October 2, 2014 nick.ace you can do this now with a C++ project. You can still use Lua with a C++ project. Guppy is looking for an App.lua type of functionality with a C++ project though I'm not 100% sure why it's needed. Maybe so changing resolutions doesn't require a recompilation? You could probably just make global functions (not part of App like App.lua) and call those directly? App.lua function Start() return true end function Loop() return true end if Start() then while Loop() do end end Leadwerks::Interpreter::ExecuteFile() would probably let you load an App.lua that looks like the above to start the code. If you wanted the C++ Start() & Loop() then maybe Leadwerks::Interpreter::EvaluateString("Loop()"); (and Start()) after Executing the file first to load the functions into the global table would work. Quote Link to comment Share on other sites More sharing options...
nick.ace Posted October 2, 2014 Share Posted October 2, 2014 I know you can use Lua in a C++ project, but I want to do something very similar to what Guppy is doing, where App.lua is being wrapped into C++ code. Basically, then you can program App.lua in Lua (so its quick for testing in the editor) but then you can add extra functionality with C++ libraries. Josh once told me it was possible and quite simple to do this, but I haven't had the time or need to try it out just yet. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 2, 2014 Share Posted October 2, 2014 How about something like this App.lua App = {} function App:Start() return true end function App:Loop() return true end In C++ bool App:Start() { Leadwerks::Interpreter::ExecuteFile("App.lua") // now you can push the App table and call it's Start() function and get it's return value and return that or Leadwerks::Interpreter::EvaluateString("App:Start()"); } bool App:Loop() { // again push App table and call Loop() and get return value and return that here or Leadwerks::Interpreter:EvaluateString("App:Loop()"); } 1 Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted October 2, 2014 Share Posted October 2, 2014 Just copy the code from the C++ source files of a Lua project and replace the C++ source files in your C++ project with the ones from the Lua project, then use the normal App.lua file from a Lua project and edit it as you please, this would make it behave the same way as a Lua project but you'd still be able to code C++ in your project. This is what I did, I find it works the best. 3 Quote Link to comment Share on other sites More sharing options...
nick.ace Posted October 2, 2014 Share Posted October 2, 2014 That looks like it would work well. Thanks Rick! I'll test it out later when I get time. Is the Interpreter class somewhere in the documentation? Could you not just copy the code from the C++ source files of a Lua project and replace your C++ source files with the ones from the Lua project, then App.lua would be the same as if it were a Lua project but you'd still be able to code C++ in your project. Oh I hadn't thought about that. Where are these C++ source files located? Quote Link to comment Share on other sites More sharing options...
Rick Posted October 2, 2014 Share Posted October 2, 2014 Yeah do what Crazy says. It basically is what I was saying but it creates the App table inside C++ vs the App.lua file. It's funny that the C++ source is still there for Lua projects but no VS project is created. Interesting. Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted October 2, 2014 Share Posted October 2, 2014 That looks like it would work well. Thanks Rick! I'll test it out later when I get time. Is the Interpreter class somewhere in the documentation? Oh I hadn't thought about that. Where are these C++ source files located? Same place as the C++ project's source files. Leadwerks/Projects/<Your Project>/Source/ Quote Link to comment Share on other sites More sharing options...
nick.ace Posted October 2, 2014 Share Posted October 2, 2014 Oh I see! Thanks! This solves a ton of issues going forward. Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted October 2, 2014 Share Posted October 2, 2014 Oh I see! Thanks! This solves a ton of issues going forward. Not a problem, good luck with your future projects! Quote Link to comment Share on other sites More sharing options...
Guppy Posted October 2, 2014 Author Share Posted October 2, 2014 Just copy the code from the C++ source files of a Lua project and replace the C++ source files in your C++ project with the ones from the Lua project, then use the normal App.lua file from a Lua project and edit it as you please, this would make it behave the same way as a Lua project but you'd still be able to code C++ in your project. This is what I did, I find it works the best. Oh I honestly didnt even look for that do not make much sende for the c++ code to be there, but very handy that it is Quote 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 More sharing options...
Crazycarpet Posted October 2, 2014 Share Posted October 2, 2014 Oh I honestly didnt even look for that do not make much sende for the c++ code to be there, but very handy that it is Yeah, I was quite happy to see it there haha, hope it helps! Good luck! 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.