LibRPC Examples: Difference between revisions
Line 22: | Line 22: | ||
Let us see an example. Suppose that in roottable of server a table 'C' exists which has a slot named 'a' whose value is 3. | Let us see an example. Suppose that in roottable of server a table 'C' exists which has a slot named 'a' whose value is 3. | ||
Now we are printing that value on server console from npc ( npc must be admin to print. Not only print, but actually for executing any functions remotely ) | Now we are printing that value on server console from npc ( npc must be admin to print. Not only print, but actually for executing any functions remotely ) | ||
Server code: | |||
<source>print(C.rawget("a"))</source> | |||
Corresponding remote function call: | |||
<source> | <source> | ||
RFC("print")( Fa("rawget")( F("rawget")("C"), "a" ) ) | RFC("print")( Fa("rawget")( F("rawget")("C"), "a" ) ) | ||
</source> | </source> |
Revision as of 00:27, 8 June 2023
The new version of LibRPC (of this article) is about to be released
New functions Fa, RFCa was added to library for raw calling of functions with a specified environment class or instance. Earlier the 'this' was always the roottable. By using "compilestring", one do not need Fa and RFCa.
The Problem
F("MyFunction")(p1, p2, ... )
MyFunction.call(getroottable(), p1, p2, ... )
Suppose i want to callMyFunction.call(m, p1, p2, ... )
where m is a table other than roottable. Then it was not possible.
It is for this reason that new function Fa is introduced.
The Working
This leads to error
Fa("MyFunction")(m, p1, p2, ... )
because the key MyFunction will be looked inside table m. So if MyFunction is in roottable, the correct code will be
Fa(F("rawget")("MyFunction"))(m, p1, p2, ... )
When the parameter is not "string", then it will work as expected.
Example One
Let us see an example. Suppose that in roottable of server a table 'C' exists which has a slot named 'a' whose value is 3. Now we are printing that value on server console from npc ( npc must be admin to print. Not only print, but actually for executing any functions remotely ) Server code:
print(C.rawget("a"))
Corresponding remote function call:
RFC("print")( Fa("rawget")( F("rawget")("C"), "a" ) )