Jump to content

Running App.lua in C++ version?


Guppy
 Share

Recommended Posts

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"

  • Upvote 1

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

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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()");
}

  • Upvote 1
Link to comment
Share on other sites

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.

  • Upvote 3
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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 :)

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...