Pages: 1
  Print  
Author Topic: template in enigma_user  (Read 2612 times)
Offline (Male) WizzardMaker
Posted on: February 12, 2015, 05:33:31 am
Member
Joined: Feb 2015
Posts: 35

View Profile
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:
Code: [Select]
//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?
Logged
Offline (Unknown gender) TheExDeus
Reply #1 Posted on: February 12, 2015, 05:42:24 am

Developer
Joined: Apr 2008
Posts: 1860

View Profile
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++).
Logged
Offline (Male) WizzardMaker
Reply #2 Posted on: February 12, 2015, 06:53:06 am
Member
Joined: Feb 2015
Posts: 35

View Profile
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
« Last Edit: February 12, 2015, 07:24:17 am by WizzardMaker » Logged
Offline (Unknown gender) TheExDeus
Reply #3 Posted on: February 12, 2015, 07:35:09 am

Developer
Joined: Apr 2008
Posts: 1860

View Profile
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.
Logged
Offline (Male) WizzardMaker
Reply #4 Posted on: February 12, 2015, 08:28:39 am
Member
Joined: Feb 2015
Posts: 35

View Profile
FuncType is a Function Pointer.
Logged
Offline (Unknown gender) TheExDeus
Reply #5 Posted on: February 12, 2015, 11:54:59 am

Developer
Joined: Apr 2008
Posts: 1860

View Profile
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).
Logged
Offline (Male) WizzardMaker
Reply #6 Posted on: February 12, 2015, 01:08:12 pm
Member
Joined: Feb 2015
Posts: 35

View Profile
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)
Logged
Offline (Unknown gender) TheExDeus
Reply #7 Posted on: February 12, 2015, 03:57:44 pm

Developer
Joined: Apr 2008
Posts: 1860

View Profile
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?
« Last Edit: February 12, 2015, 04:34:51 pm by TheExDeus » Logged
Offline (Male) WizzardMaker
Reply #8 Posted on: February 13, 2015, 03:59:11 am
Member
Joined: Feb 2015
Posts: 35

View Profile
Yeah, but I haven't tried your Method, I used this:
Code: [Select]
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.
Logged
Offline (Male) WizzardMaker
Reply #9 Posted on: February 13, 2015, 04:07:11 am
Member
Joined: Feb 2015
Posts: 35

View Profile
Hm I tested it and the compiler throws this error:
Code: [Select]
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);
         ^
Logged
Offline (Male) WizzardMaker
Reply #10 Posted on: February 13, 2015, 04:25:25 am
Member
Joined: Feb 2015
Posts: 35

View Profile
I think I found a way to avoid it.
I could use a struct to get many types like this:
Code: [Select]
struct functype{
operator const std::function<int(int)>();
        ...
        ...
};
And then I can use the struct functype
EDIT:
Nope that didn't work
« Last Edit: February 13, 2015, 04:46:27 am by WizzardMaker » Logged
Pages: 1
  Print