1 | // This file is a part of the Framsticks GDK library.
|
---|
2 | // Copyright (C) 2002-2011 Szymon Ulatowski. See LICENSE.txt for details.
|
---|
3 | // Refer to http://www.framsticks.com/ for further information.
|
---|
4 |
|
---|
5 | #include "paramvmobj.h"
|
---|
6 | #include "collectionobj.h"
|
---|
7 |
|
---|
8 | #define FIELDSTRUCT ParamVMObj
|
---|
9 | static ParamEntry paramvmobj_paramtab[]=
|
---|
10 | {
|
---|
11 | {"Interface",1,19,"Interface","Used to query for object member descriptions. Example:\nvar iface=Interface.makeFrom(someobject); var description=\"this object has \"+iface.properties+\" properties, first property is \"+iface.getId(0);"},
|
---|
12 | {"name",0,2+PARAM_NOSTATIC,"object name","s",GETONLY(name),},
|
---|
13 | {"properties",0,2+PARAM_NOSTATIC,"property count","d",GETONLY(props),},
|
---|
14 | {"groups",0,2+PARAM_NOSTATIC,"group count","d",GETONLY(groups),},
|
---|
15 | {"get",0,PARAM_NOSTATIC,"value of item #","p x(d index)",PROCEDURE(p_get),},
|
---|
16 | {"getId",0,PARAM_NOSTATIC,"id for item #","p s(d index)",PROCEDURE(p_getid),},
|
---|
17 | {"getName",0,PARAM_NOSTATIC,"name for item #","p s(d index)",PROCEDURE(p_getname),},
|
---|
18 | {"getGroup",0,PARAM_NOSTATIC,"group # for item #","p d(d index)",PROCEDURE(p_getgroup),},
|
---|
19 | {"getGroupName",0,PARAM_NOSTATIC,"group name for group #","p s(d index)",PROCEDURE(p_getgrname),},
|
---|
20 | {"getType",0,PARAM_NOSTATIC,"type for item #","p s(d index)",PROCEDURE(p_gettype),},
|
---|
21 | {"getFlags",0,PARAM_NOSTATIC,"flags for item #","p d(d index)",PROCEDURE(p_getflags),},
|
---|
22 | {"getHelp",0,PARAM_NOSTATIC,"help for item #","p s(d index)",PROCEDURE(p_gethelp),},
|
---|
23 | {"findId",0,PARAM_NOSTATIC,"item # for id","p d(s name)",PROCEDURE(p_findid),},
|
---|
24 | {"findGroupId",0,PARAM_NOSTATIC,"group # for group name","p d(s name)",PROCEDURE(p_findgroupid),},
|
---|
25 | {"findIdInGroup",0,PARAM_NOSTATIC,"item # for id in group","p d(s name,x group name or index)",PROCEDURE(p_findidingroup),},
|
---|
26 | {"makeFrom",0,2,"get interface object","p oInterface(o)",PROCEDURE(p_make),},
|
---|
27 | {"set",0,PARAM_NOSTATIC,"set value of item #","p(d index,x value)",PROCEDURE(p_set),},
|
---|
28 | {"setDefault",0,PARAM_NOSTATIC,"set default value for item #","p(d index)",PROCEDURE(p_setDef),},
|
---|
29 | {"setAllDefault",0,PARAM_NOSTATIC,"set default values for all items","p()",PROCEDURE(p_setAllDef),},
|
---|
30 | {"invoke",0,PARAM_NOSTATIC,"invoke action","p(x function name or index,oVector arguments)",PROCEDURE(p_call)},
|
---|
31 | {0,0,0,},
|
---|
32 | };
|
---|
33 |
|
---|
34 | #undef FIELDSTRUCT
|
---|
35 |
|
---|
36 | ParamVMObj::ParamVMObj(ParamInterface *pi):iface(pi),par(paramvmobj_paramtab,this)
|
---|
37 | {}
|
---|
38 |
|
---|
39 | ExtObject ParamVMObj::makeObject(ParamInterface *pi)
|
---|
40 | {
|
---|
41 | ParamVMObj *o=new ParamVMObj(pi);
|
---|
42 | return ExtObject(&o->par,o);
|
---|
43 | }
|
---|
44 |
|
---|
45 | void ParamVMObj::p_make(ExtValue *args,ExtValue *ret)
|
---|
46 | {
|
---|
47 | ParamInterface *pi=args->getObject().getParamInterface();
|
---|
48 | if (pi)
|
---|
49 | ret->setObject(makeObject(pi));
|
---|
50 | else
|
---|
51 | ret->setEmpty();
|
---|
52 | }
|
---|
53 |
|
---|
54 | int ParamVMObj::findGroupId(const char* name)
|
---|
55 | {
|
---|
56 | for(int i=0;i<iface->getGroupCount();i++)
|
---|
57 | if (!strcmp(iface->grname(i),name))
|
---|
58 | return i;
|
---|
59 | return -1;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void ParamVMObj::p_findgroupid(ExtValue *args,ExtValue *ret)
|
---|
63 | {
|
---|
64 | const SString &s=args[0].getString();
|
---|
65 | ret->setInt(findGroupId((const char*)s));
|
---|
66 | }
|
---|
67 |
|
---|
68 | void ParamVMObj::p_findidingroup(ExtValue *args,ExtValue *ret)
|
---|
69 | {
|
---|
70 | ExtValue& v=args[0];
|
---|
71 | const SString& s=args[1].getString();
|
---|
72 | int g;
|
---|
73 | if (v.type==TInt)
|
---|
74 | g=v.getInt();
|
---|
75 | else
|
---|
76 | g=findGroupId((const char*)v.getString());
|
---|
77 | if (g<0)
|
---|
78 | {ret->setInt(-1);return;}
|
---|
79 | for(int i=0;i<iface->getPropCount();i++)
|
---|
80 | if (iface->group(i)==g)
|
---|
81 | if (!strcmp(iface->id(i),s))
|
---|
82 | {ret->setInt(i);return;}
|
---|
83 | ret->setInt(-1);
|
---|
84 | }
|
---|
85 |
|
---|
86 | void ParamVMObj::p_call(ExtValue *args,ExtValue *ret)
|
---|
87 | {
|
---|
88 | if (!iface) return;
|
---|
89 | ExtValue& prop=args[1];
|
---|
90 | int p;
|
---|
91 | if (prop.type==TInt) p=prop.getInt(); else p=iface->findId(prop.getString());
|
---|
92 | if (p<0) return;
|
---|
93 | const ExtValue& a=args[0];
|
---|
94 | const ExtObject& o=a.getObject();
|
---|
95 | ParamInterface *argstype=o.getParamInterface();
|
---|
96 | ExtValue *useargs=0;
|
---|
97 | VectorObject* v;
|
---|
98 | ExtValue *tmpmem=0;
|
---|
99 | int n=0;
|
---|
100 | if (argstype && (argstype==&VectorObject::par))
|
---|
101 | {
|
---|
102 | v=(VectorObject*)o.getTarget();
|
---|
103 | n=v->data.size();
|
---|
104 | }
|
---|
105 | if (n)
|
---|
106 | {
|
---|
107 | tmpmem=new ExtValue[n];
|
---|
108 | useargs=tmpmem;
|
---|
109 | for(int i=0;i<n;i++)
|
---|
110 | tmpmem[i]=*(v->get(i));
|
---|
111 | }
|
---|
112 | iface->call(p,useargs,ret);
|
---|
113 | if (n)
|
---|
114 | delete[] useargs;
|
---|
115 | }
|
---|
116 |
|
---|