[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Accessing structures in structures
- From: Matthias Isele <matthias.isele@...>
- Date: Thu, 26 Oct 2006 10:03:54 +0200
Jerome Vuarand schrieb:
It would be easier to answer with a better whole image of your system. How do you create structure? How is the get implemented?
I'm designing a tool to test OPC-clients. OPC is a standard in
industrial communication. My tool acts as a server and a client at the
same time.
--------------- ---------- --------
| Client to test | <---->| MyTool | <-----> | Server |
--------------- ---------- --------
Now I'm simulating errors on the server side by not just passing the
data through my tool but changing some of the data via lua scripts. This
way the client is tested (e.g. if it indicates the correct error codes).
I usually don't have to create the structs as I get all the data
(structures and arrays) from the server and just change some values
(e.g. error codes) via lua scripts.
structB.anotherStruct.a
-- is equivalent to
structB["anotherStruct"]["a"]
-- or
local tmpA = structB["anotherStruct"]
tmpA["a"] -- tmpA should be a reference to structA
That might be a solution but I don't like the notation because these scripts are edited by the users of the tool and should be as easy as possible.
I'll show you an error injection script that already works (except for the struct thing) just to give a you an idea.
-- Example1:
-- for every other item set error code to a failure, quality bad and
value to VT_EMPTY
-- client should indicate an error for every other item
function OnDataChange(dwTransid, hGroup, hrMasterquality, hrMastererror,
dwCount, phClientItems, pvValues, pwQualities, pftTimeStamps, structA,
pErrors)
for i=0,dwCount-1 do
if i % 2 == 0 then -- change every second items
pErrors[i] = OPC_E_BADTYPE; -- set error code
local var = pvValues[i];
VariantClear(var); -- set value to VT_EMPTY
pwQualities[i] = OPC_QUALITY_BAD; -- set quality bad
end
-- there will be something like this here
structA.anotherStruct.xyz = 12345
end
hrMasterquality = S_FALSE;
hrMastererror = S_FALSE; return dwTransid, hGroup, hrMasterquality,
hrMastererror, dwCount, phClientItems, pvValues, pwQualities,
pftTimeStamps, structA, pErrors end
So you just have to make sure the get method for structB returns a reference to structA. As said above the exact way to do this highly depend on the way you create both structs and how getters are implemented.
In your example you don't seem to create any userdata or table, you just access to the module tables themselves. So I don't understand why you would use structB.anotherStruct instead of directly structA, since both structA and structB are singletons.
I'd like to but I get the data this way.
Thanks,
Matthias