libFAUDES

Sections

Index

lbp_1_extension.cpp

Go to the documentation of this file.
00001 /** @file lbp_1_extension.cpp 
00002 
00003 Registering a lua script with the libFAUDES run-time interface 
00004 
00005 This tutorial loads a luascript from file an registers it
00006 with the libFAUDES run-time interface. Thus, the script can be
00007 invoked by an application in the same way as built in functions.
00008 
00009 @ingroup Tutorials
00010 
00011 @include lbp_1_extension.cpp
00012 
00013 */
00014 
00015 
00016 
00017 // libfaudes include
00018 #include "libfaudes.h"
00019 
00020 // luafaudes plugin 
00021 #include "libluafaudes.h"
00022 
00023 // we make the faudes namespace available to our program
00024 using namespace faudes;
00025 
00026 
00027 /////////////////
00028 // main program
00029 /////////////////
00030 
00031 
00032 int main (int argc, char **argv) {
00033 
00034   // load std registry for data types
00035   LoadRegistry("../../../include/libfaudes.rti");
00036 
00037   // initialize a lua function definition from file
00038   LuaFunctionDefinition lfdef1;
00039   lfdef1.Read("data/largegen.rti");
00040 
00041   // report to console
00042   std::cout << "################################\n";
00043   std::cout << "# lua extension from rti file\n";
00044   lfdef1.Write();
00045   std::cout << "################################\n";
00046 
00047   // run syntax check on script
00048   std::string err=lfdef1.SyntaxCheck();
00049   if(err=="")
00050     std::cout << "script seems ok\n";
00051   else {
00052     std::cout << err << "\n";
00053     return 1;
00054   }
00055 
00056   // test faudes type interface (assignment/equality)
00057   LuaFunctionDefinition lfdef2;
00058   lfdef2 = lfdef1;
00059   if(lfdef2!=lfdef1) {
00060     std::cout << "# ERR: the two definitions should be equal\n";
00061     exit(1);
00062   }
00063 
00064   // report to console
00065   std::cout << "################################\n";
00066   std::cout << "# copy of lua extension\n";
00067   lfdef2.Write();
00068   std::cout << "################################\n";
00069 
00070 
00071   // instantiate a function object 
00072   faudes::Function* fnct = lfdef2.NewFunction();
00073 
00074   // prepare arguments
00075   Integer cntq=10;
00076   Integer cnts=5;
00077   Generator gres;
00078 
00079   // set argumants
00080   fnct->Variant(0);
00081   fnct->ParamValue(0,&cntq);
00082   fnct->ParamValue(1,&cnts);
00083   fnct->ParamValue(2,&gres);
00084 
00085   // execute lua script
00086   fnct->Execute();
00087 
00088   // report statistics on result
00089   std::cout << "################################\n";
00090   std::cout << "# statistics \n";
00091   gres.SWrite();
00092   std::cout << "################################\n";
00093 
00094 }
00095 
00096 

libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3