|
Go to the documentation of this file.
55 typedef void *(*swig_converter_func)( void *, int *);
93 if(iter-> type == from) {
94 if(iter == ty-> cast) break;
118 if(!lua_isuserdata(L,index)) return NULL;
120 if(!lua_getmetatable(L,index)) return NULL;
122 lua_pushstring(L, ".type");
124 if(!lua_isstring(L,-1)) { lua_pop(L,2); return NULL;};
125 const char* ftype = lua_tostring(L,-1);
126 if(!ftype) {lua_pop(L,2); return NULL;};
130 return (swig_lua_userdata*) lua_touserdata(L,index);
150 while(src<res.length()) {
151 if(isalnum(res.at(src))) {res[dst++]=res[src++]; continue;}
153 for(;src<res.length();src++)
154 if(isalnum(res.at(src))) break;
185 FD_DLB( "LuaFunctionDefinition::LuaFunctionDefinition("<< this<< "): name " << name);
186 FD_DLB( "LuaFunctionDefinition::LuaFunctionDefinition("<< this<< "): proto " << mpFunction);
187 FD_DLB( "LuaFunctionDefinition::LuaFunctionDefinition("<< this<< "): has def " << mpFunction->Definition());
195 FD_DLB( "LuaFunctionDefinition::LuaFunctionDefinition(copy)");
201 FD_DLB( "LuaFunctionDefinition::DoAssign()");
210 FD_DLB( "LuaFunctionDefinition::DoAssign("<< this<< "): name " << mName);
211 FD_DLB( "LuaFunctionDefinition::DoAssign("<< this<< "): proto " << mpFunction);
227 FD_DLB( "LuaFunctionDefinition::Clear(): " << Name());
268 FD_DLB( "LuaFunctionDefinition::SyntaxCheck(): no variants defined, evaluate");
274 std::string err = "";
278 FD_DLB( "LuaFunctionDefinition::SyntaxCheck(): variant " <<
293 err = "cannot allocate parameters for variant " + lfnct-> Variant()->Name();
308 std::string err = "";
327 FD_DLB( "LuaFunctionDefinition::Install(): " << Name());
331 FD_DLB( "LuaFunctionDefinition::Install(): no signatures for fnct " << Name());
336 std::string lfname = Name();
338 size_t pos= CType().find( "faudes::");
339 if(pos!=std::string::npos)
340 lfname= CType().substr(std::string( "faudes::").length());
344 std::vector< std::string > lffnct;
345 std::vector< int > lfparcnt;
346 std::vector< std::vector<std::string> > lfparams;
347 std::vector< std::vector<Parameter::ParamAttr> > lfattrib;
348 std::vector< std::vector<bool> > lfretval;
349 std::vector< std::vector<bool> > lfparval;
359 for( int j=0; j<sigi. Size(); j++) {
361 std::string ftype=sigi. At(j). Type();
389 lfparams.at(i).push_back(ftype);
390 lfattrib.at(i).push_back(fattr);
391 lfretval.at(i).push_back(fcret);
392 lfparval.at(i).push_back(fcpar);
395 if(( int) lfparams.at(i).size()!=sigi. Size()) {
396 FD_WARN( "LuaFunctionDefinition::Install(): cannot interpret signature \"" << sigi. Name() << "\"");
402 lfparcnt.at(i)=parcnt;
404 FD_DLB( "LuaFunctionDefinition::Install(): #" << lffnct.size() << " valid signatures");
408 std::vector< std::string > lftest1;
409 std::vector< std::string > lftest2;
410 std::vector< std::string > lfcall;
411 std::vector< std::string > lfsig;
412 for( unsigned int i=0; i<lffnct.size(); i++) {
414 std::string test1= "(arg['n']==" + ToStringInteger(lfparcnt.at(i)) + ")" ;
416 for( unsigned int j=0; j<lfparams.at(i).size(); j++) {
417 if(!lfparval.at(i).at(j)) continue;
420 std::string ltype= "userdata";
421 if(lfparams.at(i).at(j) == "Integer") ltype= "number";
422 if(lfparams.at(i).at(j) == "Boolean") ltype= "bool";
423 if(lfparams.at(i).at(j) == "String") ltype= "string";
424 test1=test1 + "(type(arg[" + ToStringInteger(pj) + "])=='" + ltype + "')";
426 lftest1.push_back(test1);
428 std::string test2= "";
430 for( unsigned int j=0; j<lfparams.at(i).size(); j++) {
431 if(!lfparval.at(i).at(j)) continue;
433 if(lfparams.at(i).at(j) == "Integer") continue;
434 if(lfparams.at(i).at(j) == "Boolean") continue;
435 if(lfparams.at(i).at(j) == "String") continue;
436 if(test2.size()>0) test2=test2+ " and ";
437 test2=test2 + "faudes.TypeTest(\"" + lfparams.at(i).at(j) + "\", arg[" + ToStringInteger(pj) + "])";
439 lftest2.push_back(test2);
441 std::string call= lffnct.at(i) + "(";
443 for( unsigned int j=0; j<lfparams.at(i).size(); j++) {
444 if(!lfparval.at(i).at(j)) continue;
446 if(pj>1) call = call + ", ";
450 lfcall.push_back(call);
452 std::string nsig = " " + lfname + "(";
453 bool leftcomma = false;
454 bool rightcomma = false;
455 for( unsigned int j=0; j<lfparams.at(i).size(); j++) {
457 if(lfretval.at(i).at(j)) {
458 if(leftcomma) nsig = "," + nsig;
459 nsig=lfparams.at(i).at(j) + nsig;
463 if(lfparval.at(i).at(j)) {
464 if(rightcomma) nsig += ", ";
466 nsig += sigi. At(j). Str();
471 lfsig.push_back(nsig);
476 for( unsigned int i=0; i< lfsig.size(); i++) {
477 std::string topic= PlugIn();
479 if(topic.length()>0) topic.at(0)=toupper(topic.at(0));
480 if(key1.length()>0) key1.at(0)=toupper(key1.at(0));
487 std::stringstream lfwrap;
494 lfwrap << "function faudes." << lfname << "(...)" << std::endl;
495 for( unsigned int i=0; i< lftest1.size(); i++) {
496 lfwrap << " if (" << lftest1.at(i) << ") then " << std::endl;
497 lfwrap << " if (" << lftest2.at(i) << ") then " << std::endl;
498 lfwrap << " return faudes." << lfcall.at(i) << std::endl;
499 lfwrap << " end" << std::endl;
500 lfwrap << " end" << std::endl;
502 lfwrap << " faudes.Error([[" << lfname << ": parameter mismatch: expected signature(s): " << std::endl;
503 for( unsigned int i=0; i< lfsig.size(); i++) {
504 lfwrap << lfsig.at(i) << std::endl;
506 lfwrap << "]])" << std::endl;
507 lfwrap << "end" << std::endl;
512 FD_DLB( "LuaFunctionDefinition:Install(): code: done");
515 int errexec=luaL_dostring(pLL,lfwrap.str().c_str());
517 std::string lerr= std::string(lua_tostring(pLL, -1));
518 int c1 = lerr.find_first_of( ':');
520 int c2 = lerr.find_first_of( ':',c1+1);
522 std::string line = lerr.substr(c1+1,c2-c1-1);
524 lerr= "error in Lua script: line " + line + ": " + lerr.substr(c2+2);
526 throw Exception( "LuaFunctionDefinition::Install(): " + Name(), lerr, 49);
532 FD_DLB( "LuaFunctionDefinition::DoRead()");
536 std::string label=rLabel;
537 if(label== "") label= "LuaFunctionDefinition";
547 FD_DLB( "LuaFunctionDefinition::Register(): file " << rFilename);
550 while(tr. Peek(token)) {
551 if(!token. IsBegin( "LuaFunctionDefinition")) {
557 FD_DLB( "LuaFunctionDefinition::Register(): found " << plfd-> Name());
559 FD_DLB( "LuaFunctionDefinition::Register(): skipping doublet " << plfd-> Name());
571 FD_DLB( "LuaFunctionDefinition::DoReadCore()");
584 while(rTr. Peek(code)) {
605 std::string label=rLabel;
606 if(label== "") label= "LuaFunctionDefinition";
613 FD_DLB( "LuaFunctionDefinition::DoWriteCore(): file " << rTw. FileName());
688 FD_DLB( "LuaFunction::DoTypeCheck("<< n << "): unknown type");
692 FD_DLB( "LuaFunction::DoTypeCheck("<< n << "): could not cast param value");
713 FD_DLB( "LuaFunction::DoExecute()");
732 FD_DLB( "LuaFunction::DoExecute(): done");
737 FD_DLB( "LuaFunction::SyntaxCheck()");
739 std::stringstream errstr;
740 errstr << "no valid variant";
741 throw Exception( "LuaFunction::Syntaxcheck()", errstr.str(), 47);
752 FD_DLB( "LuaFunction::SyntaxCheck(): done");
757 FD_DLB( "LuaFunction::SyntaxCheck()");
766 FD_DLB( "LuaFunction::SyntaxCheck(): done");
771 FD_DLB( "LuaFunction::DoExecuteA()");
776 int errload=luaL_loadbuffer( pLL, script, script_len, "luafaudes");
778 std::string lerr= std::string(lua_tostring( pLL, -1));
779 int c1 = lerr.find_first_of( ':');
781 int c2 = lerr.find_first_of( ':',c1+1);
783 std::string line = lerr.substr(c1+1,c2-c1-1);
785 lerr= "error in Lua script: line " + line + ": " + lerr.substr(c2+2);
788 throw Exception( "LuaFunction::DoExecuteA()", lerr, 49);
792 int errrun=lua_pcall( pLL, 0, 0, 0);
794 std::stringstream errstr;
795 errstr << "failed to run script: ";
796 errstr << std::string(lua_tostring( pLL, -1));
798 throw Exception( "LuaFunction::DoExecuteA()", errstr.str(), 49);
805 FD_DLB( "LuaFunction::DoExecuteB()");
808 lua_getglobal( pLL, "faudes");
810 if(!lua_istable( pLL,-1)) {
812 throw Exception( "LuaFunction::DoExecuteB()", "failed to load faudes table", 49);
817 lua_pushstring( pLL,fname.c_str());
819 if(!lua_isfunction( pLL,-1)) {
821 lua_getglobal( pLL,fname.c_str());
822 if(!lua_isfunction( pLL,-1)) {
823 std::stringstream errstr;
824 errstr << "missing function \"" << fname << "\"";
826 throw Exception( "LuaFunction::DoExecuteB()", errstr.str(), 49);
831 lua_pushstring( pLL, "Type");
833 if(!lua_isfunction( pLL,-1))
834 if(!lua_istable( pLL,-1)) {
836 throw Exception( "LuaFunction::DoExecuteB():", "failed to construct plain Type (1)", 49);
839 if(lua_pcall( pLL, 0, 1, 0) != 0) {
841 throw Exception( "LuaFunction::DoExecuteB():", "failed to construct plain Type (2)", 49);
847 throw Exception( "LuaFunction::DoExecuteB():", "failed to construct plain Type (3)", 49);
849 FD_DLB( "LuaFunction::DoExecuteB(): plain type is " << susr-> type-> name);
860 FD_DLB( "LuaFunction::DoExecuteC()");
874 if((ftype== "Integer") || (ftype== "Boolean") || (ftype== "String")) {
904 FD_DLB( "LuaFunction::DoExecuteC(): skip nonparameter value pos " << i);
908 if(ftype== "Integer") {
910 FD_DLB( "LuaFunction::DoExecuteC(): created ftype " << ftype);
914 if(ftype== "Boolean") {
916 FD_DLB( "LuaFunction::DoExecuteC(): created ftype " << ftype);
920 if(ftype== "String") {
922 FD_DLB( "LuaFunction::DoExecuteC(): created ftype " << ftype);
926 lua_pushstring( pLL,ftype.c_str());
928 if(!lua_isfunction( pLL,-1))
929 if(!lua_istable( pLL,-1)) {
930 std::stringstream errstr;
931 errstr << "failed to load constructor for \"" << ftype << "\"";
933 throw Exception( "LuaFunction::DoExecuteC()", errstr.str(), 49);
936 if(lua_pcall( pLL, 0, 1, 0) != 0) {
937 std::stringstream errstr;
938 errstr << "failed to construct for \"" << ftype << "\" (1)";
940 throw Exception( "LuaFunction::DoExecuteC()", errstr.str(), 49);
945 std::stringstream errstr;
946 errstr << "failed to construct for\"" << ftype << "\" (2)";
948 throw Exception( "LuaFunction::DoExecuteB()", errstr.str(), 49);
951 FD_DLB( "LuaFunction::DoExecuteC(): created stype " << susr-> type-> name << " for ftype " << ftype);
953 FD_DLB( "LuaFunction::DoExecuteC(): swig usrdata ptr " << susr-> ptr);
954 FD_DLB( "LuaFunction::DoExecuteC(): swig usrdata own flag " << susr-> own);
965 if(susr-> own) free(susr-> ptr);
970 FD_DLB( "LuaFunction::DoExecuteC(): done");
975 FD_DLB( "LuaFunction::DoExecuteD()");
981 int t2=lua_gettop( pLL);
982 for( int i= t1; i<=t2; i++) {
983 lua_pushvalue( pLL,i);
984 #ifdef FAUDES_DEBUG_LUABINDINGS
989 FD_DLB( "LuaFunction::DoExecuteD(): inspect stype " << susr-> type-> name);
990 FD_DLB( "LuaFunction::DoExecuteD(): swig usrdata ptr " << susr-> ptr);
991 FD_DLB( "LuaFunction::DoExecuteD(): swig usrdata own flag " << susr-> own);
993 FD_DLB( "LuaFunction::DoExecuteD(): faudes::Type converted ptr " << fptr);
999 FD_DLB( "LuaFunction::DoExecuteD(): detect error");
1000 std::string lerr= std::string(lua_tostring( pLL, -1));
1002 if(lerr.find( "break on application request")!=std::string::npos) {
1003 lerr= "break on application request";
1006 else if(lerr.find( "luafaudes script:")!=std::string::npos) {
1007 std::size_t c1=lerr.find( "luafaudes script:");
1008 lerr=lerr.substr(c1);
1011 else if(lerr.size()>=2) {
1012 std::size_t c1 = lerr.find_first_of( ':');
1013 if(c1==std::string::npos) c1=0;
1014 if(c1+1>=lerr.size()) c1=0;
1015 std::size_t c2 = lerr.find_first_of( ':',c1+1);
1016 if(c2==std::string::npos) c2=c1+1;
1018 std::string line = lerr.substr(c1+1,c2-c1-1);
1019 lerr= "error in Lua script: line " + line + ": " + lerr.substr(c2+2);
1024 throw Exception( "LuaFunction::DoExecuteD()", lerr, 49);
1026 FD_DLB( "LuaFunction::DoExecuteD():done ");
1032 FD_DLB( "LuaFunction::DoExecuteE()");
1035 for( int i= Variant()->Size()-1; i>=0; i--) {
1041 if(ftype== "Integer" && lua_isnumber( pLL,-1)) {
1042 FD_DLB( "LuaFunction::DoExecuteE(): retrieve type " << ftype);
1048 if(ftype== "Boolean" && lua_isboolean( pLL,-1)) {
1050 FD_DLB( "LuaFunction::DoExecuteE(): retrieved type " << ftype);
1055 if(ftype== "String" && lua_isstring( pLL,-1)) {
1057 FD_DLB( "LuaFunction::DoExecuteE(): retrieved type " << ftype);
1062 std::stringstream errstr;
1063 errstr << "invalid return values in \"" << Variant()-> Name() << "\"";
1065 throw Exception( "LuaFunction::DoExecuteE()", errstr.str(), 49);
1174 FD_DLB( "LuaState::Open()");
1179 FD_DLB( "LuaState::Done()");
1185 FD_DLB( "LuaState::Close()");
1192 lua_gc(pLL, LUA_GCSTOP, 0);
1194 luaopen_faudes_allplugins(pLL);
1195 lua_gc(pLL, LUA_GCRESTART, 0);
1202 FD_DLB( "LuaState::Insatll(): file " << rFilename);
1205 while(tr. Peek(token)) {
1207 if(!token. IsBegin( "LuaFunctionDefinition")) {
1213 FD_DLB( "LuaState::Install(): found " << lfd. Name());
1225 FD_DLB( "LuaFunction::Push()");
1226 int savetop=lua_gettop(pLL);
1229 lua_getglobal(pLL, "faudes");
1230 int ftable=lua_gettop(pLL);
1231 if(!lua_istable(pLL,-1)) {
1232 lua_settop(pLL,savetop);
1233 throw Exception( "LuaState::Push()", "failed to load faudes table", 49);
1237 lua_pushstring(pLL, "Type");
1238 lua_gettable(pLL,ftable);
1239 if(!lua_isfunction(pLL,-1)) {
1240 lua_settop(pLL,savetop);
1241 throw Exception( "LuaState::Push()", "failed to construct plain Type (1)", 49);
1244 if(lua_pcall(pLL, 0, 1, 0) != 0) {
1245 lua_settop(pLL,savetop);
1246 throw Exception( "LuaState::Push()", "failed to construct plain Type (2)", 49);
1251 lua_settop(pLL,savetop);
1252 throw Exception( "LuaState::Push()", "failed to construct plain Type (3)", 49);
1262 if(ftype== "Integer") {
1263 lua_pushnumber(pLL,(( const Integer&)*fdata));
1264 FD_DLB( "LuaState::Push(): created ftype " << ftype);
1267 else if(ftype== "Boolean") {
1268 lua_pushboolean(pLL,(( const Boolean&)*fdata));
1269 FD_DLB( "LuaState::Push(): created ftype " << ftype);
1272 else if(ftype== "String") {
1273 lua_pushstring(pLL,(( const String&)*fdata).CValue().c_str());
1274 FD_DLB( "LuaState::Push(): created ftype " << ftype);
1279 lua_pushstring(pLL,ftype.c_str());
1280 lua_gettable(pLL,ftable);
1281 if(!lua_isfunction(pLL,-1)) {
1282 std::stringstream errstr;
1283 errstr << "failed to load constructor for \"" << ftype << "\"";
1284 lua_settop(pLL,savetop);
1285 throw Exception( "LuaState::Push()", errstr.str(), 49);
1288 if(lua_pcall(pLL, 0, 1, 0) != 0) {
1289 std::stringstream errstr;
1290 errstr << "failed to construct for \"" << ftype << "\" (1)";
1291 lua_settop(pLL,savetop);
1292 throw Exception( "LuaState::Push()", errstr.str(), 49);
1297 std::stringstream errstr;
1298 errstr << "failed to construct for\"" << ftype << "\" (2)";
1299 lua_settop(pLL,savetop);
1300 throw Exception( "LuaState::Push()", errstr.str(), 49);
1303 FD_DLB( "LuaState::Push(): created stype " << susr-> type-> name << " for ftype " << ftype);
1304 FD_DLB( "LuaState::Push(): faudes parameter at " << ParamValue(i));
1305 FD_DLB( "LuaState::Push(): swig usrdata ptr " << susr-> ptr);
1306 FD_DLB( "LuaState::Push(): swig usrdata own flag " << susr-> own);
1309 FD_DLB( "LuaState::Push(): faudes plain Type converted ptr " << fptr);
1311 std::stringstream errstr;
1312 errstr << "failed cast from " << ftype;
1313 lua_settop(pLL,savetop);
1314 throw Exception( "LuaState::Push()", errstr.str(), 49);
1316 (( Type*)fptr)->Assign(*fdata);
1319 lua_replace(pLL,-2);
1320 FD_DLB( "LuaFunction::DoExecuteB(): done");
1330 FD_DLB( "LuaFunction::Pop()");
1331 int savetop=lua_gettop(pLL);
1335 if(lua_isnumber(pLL,-1)) {
1336 res= new Integer(lua_tointeger(pLL,-1));
1341 if(lua_isstring(pLL,-1)) {
1342 res= new String(lua_tostring(pLL,-1));
1347 if(lua_isboolean(pLL,-1)) {
1348 res= new Boolean(lua_toboolean(pLL,-1));
1354 lua_getglobal(pLL, "faudes");
1355 int ftable=lua_gettop(pLL);
1356 if(!lua_istable(pLL,-1)) {
1357 lua_settop(pLL,savetop);
1358 throw Exception( "LuaState::Pop()", "failed to load faudes table", 49);
1362 lua_pushstring(pLL, "Type");
1363 lua_gettable(pLL,ftable);
1364 if(!lua_isfunction(pLL,-1)) {
1365 lua_settop(pLL,savetop);
1366 throw Exception( "LuaState::Pop()", "failed to construct plain Type (1)", 49);
1369 if(lua_pcall(pLL, 0, 1, 0) != 0) {
1370 lua_settop(pLL,savetop);
1371 throw Exception( "LuaState::Pop()", "failed to construct plain Type (2)", 49);
1376 lua_settop(pLL,savetop);
1377 throw Exception( "LuaState::Pop()", "failed to construct plain Type (3)", 49);
1387 std::stringstream errstr;
1388 errstr << "unknown data type";
1389 lua_settop(pLL,savetop);
1390 throw Exception( "LuaState::Pop()", errstr.str(), 49);
1394 FD_DLB( "LuaState::Pop(): swig usrdata ptr " << susr-> ptr);
1396 FD_DLB( "LuaState::Pop(): faudes::Type converted ptr " << fptr);
1398 std::stringstream errstr;
1399 errstr << "faild to cast stype \"" << susr-> type-> name << "\" to plain Type";
1400 lua_settop(pLL,savetop);
1401 throw Exception( "LuaState::Pop()", errstr.str(), 49);
1407 FD_DLB( "LuaFunction::Pop(): done");
1420 lua_getfield(pLL, LUA_GLOBALSINDEX, gname.c_str());
1426 lua_setfield(pLL, LUA_GLOBALSINDEX, gname.c_str());
1439 FD_DLB( "LuaFunction::Evaluate()");
1442 int top = lua_gettop(pLL);
1447 if(luaL_loadbuffer(pLL, expr.c_str(), expr.size(), "string")) {
1448 cerr=std::string(lua_tostring(pLL, -1));
1454 if(lua_pcall(pLL, 0, LUA_MULTRET, 0)){
1455 cerr=std::string(lua_tostring(pLL, -1));
1460 lua_settop(pLL,top);
1461 lua_gc(pLL, LUA_GCCOLLECT, 0);
1465 lua_settop(pLL,top);
1466 throw Exception( "LuaState::Evaluate()", cerr, 49);
1480 FD_DLB( "LuaFunction::Complete(" << word << ")");
libFAUDES 2.24g
--- 2014.09.15
--- c++ api documentaion by doxygen
|