|
|
|
|
WizzardMaker
|
|
Reply #4 Posted on: February 16, 2015, 12:17:02 pm |
|
|
Joined: Feb 2015
Posts: 35
|
I made progress too... I dont have to write all functions, I just have to write many functions that let you give a function. If its possible in the future to use templates then I could let the user add more then one function, but its not. I could do the same as you and add all functions from ENIGMA but I don't have time for that
|
|
|
Logged
|
|
|
|
|
|
TheExDeus
|
|
Reply #7 Posted on: February 22, 2015, 09:50:08 am |
|
|
Joined: Apr 2008
Posts: 1860
|
instance_t is defined in "instance_system_base.h" which is included from "Universal_System/instance_iterator.h" (which is what I include in my project). There you can see that instance_t is just typedef for int. So in AngelScript I do this for all the types we have typedef'd. I do have problems with more complex types, like vararg.
r = engine->RegisterObjectType("ma_scalar", sizeof(ma_scalar), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 ); r = engine->RegisterObjectType("cs_scalar", sizeof(cs_scalar), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 ); r = engine->RegisterObjectType("as_scalar", sizeof(as_scalar), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 ); r = engine->RegisterObjectType("gs_scalar", sizeof(gs_scalar), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 ); r = engine->RegisterObjectType("char", sizeof(char), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 ); r = engine->RegisterObjectType("time_t", sizeof(time_t), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 ); r = engine->RegisterObjectType("instance_t", sizeof(instance_t), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 ); r = engine->RegisterObjectType("size_t", sizeof(size_t), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 ); r = engine->RegisterObjectType("uint32_t", sizeof(uint32_t), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 ); r = engine->RegisterObjectType("long", sizeof(long), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C); assert( r >= 0 );
Header having this:
using enigma::instance_t;
|
|
« Last Edit: February 22, 2015, 09:51:44 am by TheExDeus »
|
Logged
|
|
|
|
|
TheExDeus
|
|
Reply #9 Posted on: February 23, 2015, 05:13:24 am |
|
|
Joined: Apr 2008
Posts: 1860
|
Yeah, you need to add variant as a type. I don't know if you can do that in LUA. I can do it in AS, but it's not that trivial (as variant isn't actually that trivial).
If you need to make wrappers anyway, then you could wrap the thing like you suggest:
void draw_text(gs_scalar x, gs_scalar y, string str){ draw_text(x, y, str); //This calls draw_text(gs_scalar x, gs_scalar y, variant str) }
Then of course some things won't work, like this:
draw_text(x, y, 5.3);
Which is valid in EDL and GML, as reals can be cast to variant, but they cannot be cast to strings (stl strings have special casting functions for that). I want to implement variant and varargs in AS, but have put that on a backburner right now, as I don't actually need to use EDL in AS. I just need it working in ENIGMA so I can use the few functions I need.
|
|
|
Logged
|
|
|
|
WizzardMaker
|
|
Reply #10 Posted on: February 23, 2015, 05:43:58 am |
|
|
Joined: Feb 2015
Posts: 35
|
You could add two functions like
draw_string(int x, int y, string str); draw_value(int x, int y, int val); or you could overload the function, but I dont know if Lua supports it...
EDIT: I just tested draw_string(..., ..., string str) in lua with draw_string(..., ..., 1) and it worked, mysterious...
EDIT2: Is there a way to add my function to LGM? It's not showing in the function list.
namespace enigma_user{ lua_State* lua_start(); }
|
|
« Last Edit: February 23, 2015, 06:28:51 am by WizzardMaker »
|
Logged
|
|
|
|
TheExDeus
|
|
Reply #11 Posted on: February 23, 2015, 08:45:55 am |
|
|
Joined: Apr 2008
Posts: 1860
|
Maybe it's because of the pointer. But it should still show. Templates are the only thing I know which makes the function invisible. Sadly the parser doesn't output anywhere when LGM uses it, so we cannot tell where the error is. Where is lua_State defined? Maybe it cannot find that, so it errors. EDIT: I just tested draw_string(..., ..., string str) in lua with draw_string(..., ..., 1) and it worked, mysterious... I guess LUA can cast numbers to strings automatically.
|
|
|
Logged
|
|
|
|
|
WizzardMaker
|
|
Reply #13 Posted on: February 23, 2015, 05:29:18 pm |
|
|
Joined: Feb 2015
Posts: 35
|
And I think someone should rename the topic to something like "Enigma discussion" (maybe me, but I dont know how )
|
|
|
Logged
|
|
|
|
TheExDeus
|
|
Reply #14 Posted on: February 24, 2015, 06:42:20 am |
|
|
Joined: Apr 2008
Posts: 1860
|
What I do with pointer is abstract them. That is done in several places in ENIGMA and many extensions. For example, in the AngelScript extension I'm doing this:
unordered_map<unsigned int, asIScriptFunction*> as_functions; unsigned int as_functions_maxid = 0;
int as_function_init(int engine, string module, string function){ limit_checkv(engine, as::as_engines_maxid, "engine"); //This checks if engine exists asIScriptModule *mod = as::as_engines[engine]->GetModule(module.c_str()); asIScriptFunction *func = mod->GetFunctionByDecl(function.c_str()); as::as_functions.insert(pair<unsigned int, asIScriptFunction* >(as::as_functions_maxid, func)); return as::as_functions_maxid++; }
void as_function_destroy(int function){ limit_check(function, as::as_functions_maxid, "function"); //This checks if the function exists as::as_functions.erase(as::as_functions.find(function)); } It's not pretty or very C++'y (more like C), but that is what is required if we want everything to be integers. It does allow more error checking and gives less possibilities for crashes.
|
|
|
Logged
|
|
|
|
|