Jump to content

Cant Use C++ Only LUA


drakth
 Share

Recommended Posts

Hello everyone,

 

After while i got back with Leadwerks, and i dont know if im doing something wrong or what is happening, but i cant seem to get anything to work with C++ it seems like its only being setup to use LUA.

 

Yes, i have the standard edition :)

 

I have created an example project (download link below!), it should load the level and have a basic FPS player (hopefully it works since i cant test it!)

 

When i use one of my previous projects it works fine and i can do stuff, but when i started a new project (tried with blank and marble) it only seems to be working for LUA, not C++.

 

Download Link:

https://onedrive.live.com/redir?resid=614054867A013815!845&authkey=!APfWFon2GrPb4LU&ithint=file%2czip

 

Any help would be appreciated.

 

Thank you.

Link to comment
Share on other sites

C++ project files will be created for all new projects now. See "Projects\Windows" or "Projects\Linux" for the VS or CodeBlocks project files. :)

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

Yes, i saw the project folders, and added code to the app.cpp, but still doesn't seem to work.

 

any code after the next block of code doesn't seems to be executed until i close the window.

 

std::string scriptpath = "Scripts/Main.lua";
if (FileSystem::GetFileType("Scripts/App.Lua") == 1) scriptpath = "Scripts/App.Lua";
//Invoke the start script
if (!Interpreter::ExecuteFile(scriptpath))
{
System::Print("Error: Failed to execute script \"" + scriptpath + "\".");
return false;
}

 

This code seems to be something LUA related. From what i see on my old projects this code wasn't there before, so i guess it got added on one of lasts updates, strangely my previous projects works fine, but new ones doesn't.

 

I'm attaching the example and error file.

 

Thank you.

 

Edit: attached the zip file.

post-9082-0-99019900-1435371638_thumb.jpg

Nova.zip

Link to comment
Share on other sites

I added the World::Create() but i still get the error (and a black screen), it seems to create the world load textures and stuff but nothing appears on screen, and when pressing escape y get the same error because of the code i added in app:loop() which is weird :-/

Link to comment
Share on other sites

Hi

 

I have not tried to mix CPP and LUA that much but I think the problem is that you start the main.lua script and initiate a window with no camera since it is not defined in the map. The one you creates is added before the main.lua script have initated the world etc (I could not get this working unless I moved the create camera to after the execution of the main.lua script.

 

The problem with calling the main.lua is that it enters a loop waiting for closing the window or esc is pressed. I you still want this lua connection I had better results adding a app.lua script with a start and loop function insted of using the main.lua script.

 

Then it will execute the loop in the app.cpp program and if you inspect the window pointer and other variables, you will see that they are not initilized (sett to zero).

 

I'm not sure how to get the window pointer and context pointer since they are created in the lua script but I think if you are going to use this mix of lua and cpp you will have to know these in the loop (either remove the initilization in the main script and use a app.lua script with a simpler start function or do all the initialization in the cpp program).

 

regards

Eirik

Link to comment
Share on other sites

Hi

 

Tested this some more and create a test project whith some mixed actions.

 

1 cube created and controlled in cpp

1 cube created and controlled in the App.lua script

1 cube created designtime and controlled from attached lua script

 

Uploaded the project here http://nesje.priv.no/TestCppLua.zip

 

Hope this can help (I got some ideas testing this myself biggrin.png )

 

Regards

Eirik

Link to comment
Share on other sites

Hello thanks for your reply Eirik,

 

Yes, i got to the same conclusion, tho i wasn't trying to do a mix of LUA and C++ :P.

 

I don't think i like much the idea of not being able to choose between C++ or LUA project.

 

Someone correct me if i'm wrong, but if i don't want to use LUA i should have to remove all those code thingy about interpreter, right?

 

Yeah the LOOP thing was annoying thats why i figured it was a LUA thingy.

Link to comment
Share on other sites

Hi

 

I would go for a complete removal of the lua interpreter if You are not going to use it.

 

BR

Eirik

 

I don't think, this is possible...

I tried to get rid of LUA a few times, since it is driving me nuts that I can't really check my games for memory leaks because the LUA-interpreter allocates and disallocates memory randomly (see e.g. this thread: http://www.leadwerks.com/werkspace/topic/9505-tons-of-memory-leaks-in-leadwerks/).

Also, if you don't use LUA, this is only wasting performance and memory, so I would absolutely love to see the possibility to turn off LUA (/ to not turn it on in first place).

Link to comment
Share on other sites

I don't think, this is possible...

I tried to get rid of LUA a few times, since it is driving me nuts that I can't really check my games for memory leaks because the LUA-interpreter allocates and disallocates memory randomly (see e.g. this thread: http://www.leadwerks.com/werkspace/topic/9505-tons-of-memory-leaks-in-leadwerks/).

Also, if you don't use LUA, this is only wasting performance and memory, so I would absolutely love to see the possibility to turn off LUA (/ to not turn it on in first place).

Interesting!

Link to comment
Share on other sites

I don't think, this is possible...

I tried to get rid of LUA a few times, since it is driving me nuts that I can't really check my games for memory leaks because the LUA-interpreter allocates and disallocates memory randomly (see e.g. this thread: http://www.leadwerks.com/werkspace/topic/9505-tons-of-memory-leaks-in-leadwerks/).

Also, if you don't use LUA, this is only wasting performance and memory, so I would absolutely love to see the possibility to turn off LUA (/ to not turn it on in first place).

 

I don't see why it wouldn't be possible. Right now the C++ project uses the Lua Interpreter to load main.lua which kicks off all the lua stuff. You can just gut the C++ code and make your own game loop in C++ and that should completely remove Lua from your project given you don't attach any lua scripts to any entities in the editor. The fact that Lua may get initialized directly in LE shouldn't cause any sort of memory or performance issues if you never use it. Lua itself if not used but included is so small.

 

There used to be a C++ template but I think Josh's mindset was that if you just wanted to use C++ that means you are a competent and experienced programmer and would be able to do the stuff stated above so what's the point of providing a template for such a small % of users.

Link to comment
Share on other sites

I don't see why it wouldn't be possible. Right now the C++ project uses the Lua Interpreter to load main.lua which kicks off all the lua stuff. You can just gut the C++ code and make your own game loop in C++ and that should completely remove Lua from your project given you don't attach any lua scripts to any entities in the editor. The fact that Lua may get initialized directly in LE shouldn't cause any sort of memory or performance issues if you never use it. Lua itself if not used but included is so small.

 

I tried that but this doesn't work. As soon as leadwerks.h is included, you can't prevent the LUA-Interpreter to be started. Even if you exit right in the first line of the main-function the tools for detecting memory leaks will tell you that there are allocated chunks everywhere. There seems to be something statically initialized. In the template code, there is no line which starts the interpreter (only one that connects it) and you can only disconnect it but never destroy it.

Link to comment
Share on other sites

What tools are you using? I find it hard to believe that there are crazy memory issues with just starting up the lua libraries. If this is the case maybe there is something more efficient Josh could be doing with his code. Maybe he just assumed everyone would use Lua and so the code isn't very efficient in doing tasks if lua isn't used. ie. maybe he's calling lua functions to query things even if no scripts are ever attached to entities where it would be better to just have a boolean flag or something (I don't know as we don't have that code). This may be a chance to see if he can make this better.

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