Embedding Lua to C++ and wxWidgets using Eclipse IDE - c++

I am new to Lua so I am sorry if this is rather an easy question but it is driving me nuts. In my previous thread A simple query on calling Lua 5.2 from C++ I have used an easy C++ code to embed Lua in it. Things worked well but when I transfer that concept to a more complex project, the same code does not work. I have checked many sources but could not find a solution.
Here is my code:
#include "External/include/lua.hpp"
lua_State *luastate =NULL;
IMPLEMENT_APP(ScienceSuitApp);
bool ScienceSuitApp::OnInit()
{
luastate=luaL_newstate();
luaL_openlibs(luastate);
ScienceSuitFrame* frame = new ScienceSuitFrame(0L);
frame->Show();
return true;
}
Now when I try to compile the code, I am getting invalid arguments error for the luaL_openlibs(luastate) line. The error that the compiler gives:
Invalid arguments '
Candidates are:
void luaL_openlibs(*)
' ScienceSuitApp.cpp /ScienceLab line 33 Semantic Error
This is actually happening whenever I call a Lua function such as luaL_dostring etc.. which takes lua_State as parameter. By the way, I am using Eclipse as IDE and wxWidgets as GUI if that should give a clue. Any my configuration for this set up is:
I "think" I have solved the problem. It stems from the fact that Eclipse throws a "semantic error" and not a "syntax error". Therefore, I followed the advice from Eclipse CDT shows semantic errors, but compilation is ok. But now my question is what does it have to do with Indexing in Eclipse IDT? It feels like I am using Eclipse without knowing any of its internals.

Related

destructor not recognised by Xcode

new to this forum and to programming so please forgive any potential mistakes in my question. I am trying to code a game in c++ using SDL2 and Xcode 6.3.2. In my Game class (see below) Xcode does not recognise my destructor and gives me the error: expected member name or ';' after declaration
I have no idea what is wrong with my destructor or my code in general. My question is simply: What have I done wrong? Thanks in advance!
update:
Narrowed the issue down and ran the code in cpp.sh without any issues. Xcode still gives the error message and I am unable to build because of it. I have tried restarting my computer, deleting the derived data and cleaning the build folder but to no effect.
int main() {
class Game {
public:
Game();
~Game(); //here is the issue
};
}
update 2: Simply removed the non working code and retyped it. The error message did not reappear and the build succeeded. Xcode had probably indeed cached the error message in some strange way.
You need to have written:
Game::~Game(){
}
somewhere at the bottom, outside the class.
Then it will compile fine :)

Weird interaction: ECL throws errors on windows when TGUI tries to create an Edit Box

I am currently using TGUI (a GUI library based on SFML) together with ECL (so I can use Lisp for config and scripts). It works fine on Linux/gcc, but on Windows/MinGW ECL throws an error:
Condition of type: FLOATING-POINT-INVALID-OPERATION
#<a FLOATING-POINT-INVALID-OPERATION>
Available restarts:
1. (CONTINUE) Ignore signal
Top level in: #<process TOP-LEVEL>.
>
The point in code at which the error is thrown (minimal code that creates it) is:
empty_panel = tgui::Panel::Ptr(*cur_gui, "empty_panel");
empty_panel->setSize(cfg.res.x, cfg.res.y);
empty_panel->setBackgroundColor(sf::Color::Transparent);
tgui::EditBox::Ptr txt_test(*empty_panel, "txt_test");
Note that I can create Labels, Buttons, Checkboxes, etc. just fine - but once I try to make an Edit Box, ECL complains.
This does not make any sense to me whatsoever. TGUI and ECL are completely unrelated libraries, not sharing functions or depending on each other in any way that I know of. Does anyone have an idea what might cause this behavior?
EDIT: Just did a complete recompile of SFML, TGUI and ECL with the most recent version of MinGW, and it still breaks in exactly the same way. So I've decided that enough is enough and I'll rewrite my project to use SFGUI instead.
From now on, this question is of academic interest only.
I finally found out what might have happened there:
While ECL is running, it tries to handle all uncaught exceptions, segfaults, etc that happen on it's watch, even if they never interact with LISP. And the way it handles them is by immediately jumping to the REPL when they occur, to allow for manual debugging.
Which is the sane thing to do for anything that happens because of errors in a LISP program or C/C++ functions that interact with it, but is mildly confusing when the error happens in unrelated C++ code (like the presumed bug in TGUI).
Minimal way to reproduce: Load ECL and try some invalid operation, like so:
#include <ecl/ecl.h>
int main(int argc, char **argv) {
cl_boot(argc, argv);
atexit(cl_shutdown);
int x = 1/0;
return EXIT_SUCCESS; }

Building RakNet C# Wrapper with Swig, get an annoying error at build

I know I should post this on the official RakNet forum, but I actually have, but it seems to be dead as hell.
The reason why I'm asking here is because I have no idea of C++, I'm a game developer and we're using Unity3D/C# to develop our new game, it's going to be Multiplayer and as RakNet was Open Sourced I wanted to give it a try.
So, here we go, this is the error log:
raknet_wrap.cxx(15441): error C2558: class 'RakNet::ReliabilityLayer' : no copy constructor available or copy constructor is declared 'explicit'
And the line where the error is is this:
jresult = new ReliabilityLayer((const ReliabilityLayer &)result);
Full function:
SWIGEXPORT void * SWIGSTDCALL CSharp_RakPeer_RemoteSystemStruct_reliabilityLayer_get(void * jarg1) {
void * jresult ;
RakNet::RakPeer::RemoteSystemStruct *arg1 = (RakNet::RakPeer::RemoteSystemStruct *) 0 ;
ReliabilityLayer result;
arg1 = (RakNet::RakPeer::RemoteSystemStruct *)jarg1;
result = ((arg1)->reliabilityLayer);
jresult = new ReliabilityLayer((const ReliabilityLayer &)result);
return jresult;
}
Can someone tell me why is it not working and explain it for a completely new person to C++ so I can understand the error?
(Edit) Going to also provide the ReliabilityLayer class! Here it is: http://pastebin.com/qTXedJFw
So I finally managed to build the RakNet C# DLL of the newest RakNet version.
And, as I don't want anybody with no experience on C++ to go through the madness I did through, I'm just sharing the DLL for easy use. Just import it to your project and start using it.
Here it is: https://drive.google.com/file/d/0BwuOJwLuDZfnM29DTFlLTWZWOXc/view?usp=sharing
OK to whoever is watching this and doesn't have a successful answer.
This is clearly a compiler bug in MSVC 2013 (that's what I tried).
SWIG generates the file 'RakNet_wrap.cxx' with the following line:
jresult = new ReliabilityLayer((const ReliabilityLayer &)result);
The quickest way around it is to edit this line so that it reads:
jresult = new ReliabilityLayer(result);
and hence the casting becomes implicit instead of explicit and MSVC 2013 accepts this.
The only problem is that when you hit Build, SWIG will overwrite this file and introduce the error again. So just remove the SWIG prebuild step (Alt+F7->Build Events->Pre-Build Event remove the PreBuild.bat from the command line) and build again. Now it will successfully compile and link as it should.
Don't forget to put the PreBuild.bat file again if you need to modify the source code and run SWIG again!
Also use SWIG 2.0.12; the latest version I tried (3.0.5); generates broken C# code (undefined HandleRef and IntPtr because System.Runtime.InteropServices is not either explicit nor imported via 'using' keyword).
I've raised a ticket to the SWIG project about this: https://github.com/swig/swig/issues/433

Nodejs C++ event emitter. add-on error. Non-function in MakeCallback. method = emit Abort trap: 6

I'm creating a C++ level event emitter addon for node.js. I'm getting this C++ error when including the add-on in a node.js project.
Non-function in MakeCallback. method = emit Abort trap: 6
I found this Gist with a simplified example of the same behavior:
https://gist.github.com/jedi4ever/4250746
Hoping for some general insight into why this might be caused or what this error means.
If I understand what you're trying to do correctly, you have a couple of problems in your keylogger.js file;
util.inherits(new keylogger, events.EventEmitter);
exports = keylogger;
You're trying to extend an instance, and your export statement is a bit off. This should work better to export keylogger as an instance which the test file seems to expect;
util.inherits(keylogger, events.EventEmitter);
exports.keylogger = new keylogger();

Include Alien in portable app, C++

Ok, I've searched quite a bit, but seem unable to find an answer or example for how to achieve this.
Basically, I have an app that is designed to be portable (built using VC++ in VS2010, but no MFC or managed components, raw WinAPI). I have Lua 5.2 built into it and allow the user to write scripts inside the application. I have multiple glued functions which are exposed to the Lua scripts which handle various WinAPI calls.
However, what I'd like to be able to do is allow the user to write a script in which looks something like this:
require[[Alien/alien]]
local mb = alien.User32.MessageBoxA
mb:types{ 'long', 'long', 'string', 'string', 'long' }
print(mb(0, "Hello World!", "Test", 64))
I simply cannot seem to find a way to do this. I do not want to require the user to install Lua for Windows and, ideally, there be no core.dll and struct.dll from alien; when I tried to do something with those DLLs in ./alien/, it was crashing in Lua5.1.dll because I had LuaForWindows installed, I uninstalled LFW, and then it just states that Lua5.1.dll is missing. I have Lua 5.2 built into my app, so obviously the core/struct DLLs from the Alien rock are expecting Lua5.1.dll to be in the path.
I made a worthless attempt to try to including the Alien src into the project, but doesn't seem to work that way either.
Any ideas would be greatly appreciated. I'd prefer it all be contained in my app, but I'll settle for a solution which involves including the libraries in my project to build and bundle in the distribution if that's the only alternative.
Thanks!
UPDATE:
Ok, thank you Ben Voigt! I think I'm almost there. I've pulled in core.c and struct.c and made sure all the paths are there for libffi. Everything compiles without issue, until I try to call luaopen_alien_core in core.c (the alien.core src file), claiming the identifier is undeclared. I've tried to declare the function signature in my separate source file that's trying to make the call, the compile gets further, but fails complaining of an unresolved external.
Clearly this is likely now a general C++ issue (as I'm only a novice in this area). Here's the general idea of what I have:
//core.c (from Alien project)
(...)
int luaopen_alien_core(lua_State *L) {
alien_register_library_meta(L);
alien_register_callback_meta(L);
alien_register_function_meta(L);
alien_register_buffer_meta(L);
lua_getglobal(L, "alien");
if(lua_isnil(L, -1)) {
lua_newtable(L);
lua_pushvalue(L, -1);
lua_setglobal(L, "alien");
}
lua_newtable(L);
lua_pushvalue(L, -1);
lua_setfield(L, -3, "core");
alien_register_main(L);
return 1;
}
//mysource.c (the file attempting to call luaopen_alien_core(L))
void initLua()
{
L = luaL_newstate();
luaL_openlibs(L);
luaopen_alien_core(L);
(...)
}
This fails to start compiling, issuing the error:
error C3861: 'luaopen_alien_core': identifier not found
Which makes sense, so I add the following line to myheader.h:
int luaopen_alien_core(lua_State *L);
This compiles, but fails to link with:
error LNK2001: unresolved external symbol "int __cdecl luaopen_alien_core(struct lua_State *)" (?luaopen_alien_core##YAHPEAUlua_State###Z)
I've tried several things I can think of, with my limited experience, but nothing will satisfy this error. I even tried to move the contents of core.c into mysource.c, but that creates a whole different mess and seemed to be the wrong way to go as it is.
I'm hoping, and imagining, this is something really stupid, but I'm just not sure how to get it to call luaopen_alien_core, which seems to be the final piece I need.
Thanks again!
}
I imagine that the require directive both loads a dynamic library and adds its contents to the active Lua engine.
By linking alien directly into your code, you obviate the need for the dynamic library. But the content enumeration code won't have run, and you can't use require to run it, or else it'll go looking for a DLL file (along with all the DLL dependencies).
So, you should find out what functions that require directive calls after loading the DLL, and call those when creating a Lua engine. Then it will neither be necessary nor allowed for the script to start with require [[Alien/alien]], but Alien objects will be available.