Pages: 1
Author Topic: template in enigma_user  (35,422 Views)
Offline (Unknown gender) WizzardMaker

Member
Joined: Feb 2015
Posts: 35
View profile
Posted on: February 12, 2015, 10:33:31 AM
I am trying to use a template in the include.h file for my Extension but Enigma or LGM does not recognize my function...
Here is my code:

//include.h
#include "../../var4.h"
#include <functional>
#include <luastate.h>

namespace enigma_user{
template<typename FuncType> variant luaF_execute_file(string filepath,FuncType f);
}

Is there any way to let Enigma or LGM get the function?
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #1 Posted on: February 12, 2015, 10:42:24 AM
No, sadly EGL doesn't allow templates or classes. That is why I'm waiting 100 years for the new parser. I even made a templated matrix extension that is in the ENIGMA repo, but cannot be enabled and used because of this. There are always a way around this though (think C instead of C++).
Offline (Unknown gender) WizzardMaker

Member
Joined: Feb 2015
Posts: 35
View profile
Reply #2 Posted on: February 12, 2015, 11:53:06 AM
So the only way to make this happen is using #define or am I missing something?

EDIT:
Hm... I could write multiple functions to make that happen but that not really good looking
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #3 Posted on: February 12, 2015, 12:35:09 PM
What exactly is FuncType?

And sadly as I said, EDL is basically C. So you will have to do it the C way.
I think you can use overloads though.
Offline (Unknown gender) WizzardMaker

Member
Joined: Feb 2015
Posts: 35
View profile
Reply #4 Posted on: February 12, 2015, 01:28:39 PM
FuncType is a Function Pointer.
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #5 Posted on: February 12, 2015, 04:54:59 PM
If it's just pointer, then you can use "void*". Pointers are allowed in ENIGMA and they have been working for me in the past (like passing an array to a function).
Offline (Unknown gender) WizzardMaker

Member
Joined: Feb 2015
Posts: 35
View profile
Reply #6 Posted on: February 12, 2015, 06:08:12 PM
Yeah, I know but the problem is that I want to get GML functions that can be executed in Lua like instance_create or motion_set so I cant use void* (As I know)
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #7 Posted on: February 12, 2015, 08:57:44 PM
This seems to work:
Code (edl) Select
void* a = instance_create;
But wouldn't that mean you will be able to use only one function inside LUA?
Offline (Unknown gender) WizzardMaker

Member
Joined: Feb 2015
Posts: 35
View profile
Reply #8 Posted on: February 13, 2015, 08:59:11 AM
Yeah, but I haven't tried your Method, I used this:
variant luaF_execute_file_int3(string filepath,const std::function<int(int, int, int)> &f);
I will try it and send it in here.

Thank you.
Offline (Unknown gender) WizzardMaker

Member
Joined: Feb 2015
Posts: 35
View profile
Reply #9 Posted on: February 13, 2015, 09:07:11 AM
Hm I tested it and the compiler throws this error:
In file included from C:/ProgramData/ENIGMA/API_Switchboard.h:42:0,
                 from SHELLmain.cpp:60:
./Universal_System/Extensions/Lua/include.h:25:9: error:   initializing argument 2 of 'variant enigma_user::luaF_execute_file(std::string, void*)' [-fpermissive]
variant luaF_execute_file(string filepath, void* f);
         ^
In file included from SHELLmain.cpp:109:0:
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h: In member function 'virtual variant enigma::OBJ_obj_0::myevent_create()':
C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:42:60: error: invalid conversion from 'void (*)()' to 'void*' [-fpermissive]
     luaF_execute_file("C:\\ENIGMA\\Lua\\test.lua", path_end);
                                                            ^
In file included from C:/ProgramData/ENIGMA/API_Switchboard.h:42:0,
                 from SHELLmain.cpp:60:
./Universal_System/Extensions/Lua/include.h:25:9: error:   initializing argument 2 of 'variant enigma_user::luaF_execute_file(std::string, void*)' [-fpermissive]
variant luaF_execute_file(string filepath, void* f);
         ^
Offline (Unknown gender) WizzardMaker

Member
Joined: Feb 2015
Posts: 35
View profile
Reply #10 Posted on: February 13, 2015, 09:25:25 AM
I think I found a way to avoid it.
I could use a struct to get many types like this:
struct functype{
operator const std::function<int(int)>();
        ...
        ...
};

And then I can use the struct functype
EDIT:
Nope that didn't work
Pages: 1