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;};
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);
548 TokenReader tr(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()");
579 if(token.StringValue()==
"LuaCode") {
581 rTr.ReadVerbatim(
"LuaCode",
mLuaCode);
585 if(token.StringValue()==
"LuaFile") {
586 rTr.ReadBegin(
"LuaFile");
587 std::string
mLuaFile=rTr.ReadString();
589 rTr.ReadEnd(
"LuaFile");
597 std::string label=rLabel;
598 if(label==
"") label=
"LuaFunctionDefinition";
605 FD_DLB(
"LuaFunctionDefinition::DoWriteCore(): file " << rTw.FileName());
610 rTw.WriteVerbatim(
"LuaCode",
mLuaCode);
614 rTw.WriteBegin(
"LuaFile");
616 rTw.WriteEnd(
"LuaFile");
640 FD_DLB(
"LuaFunction::LuaFunction(): fdef " << pFuncDef);
651 pLuaFuncDef =
dynamic_cast<const LuaFunctionDefinition*
>(fdef);
678 FD_DLB(
"LuaFunction::DoTypeCheck("<< n <<
"): unknown type");
682 FD_DLB(
"LuaFunction::DoTypeCheck("<< n <<
"): could not cast param value");
703 FD_DLB(
"LuaFunction::DoExecute()");
722 FD_DLB(
"LuaFunction::DoExecute(): done");
727 FD_DLB(
"LuaFunction::SyntaxCheck()");
729 std::stringstream errstr;
730 errstr <<
"no valid variant";
731 throw Exception(
"LuaFunction::Syntaxcheck()", errstr.str(), 47);
742 FD_DLB(
"LuaFunction::SyntaxCheck(): done");
747 FD_DLB(
"LuaFunction::SyntaxCheck()");
756 FD_DLB(
"LuaFunction::SyntaxCheck(): done");
761 FD_DLB(
"LuaFunction::DoExecuteA()");
766 int errload=luaL_loadbuffer(
pLL, script, script_len,
"luafaudes");
768 std::string lerr= std::string(lua_tostring(
pLL, -1));
769 int c1 = lerr.find_first_of(
':');
771 int c2 = lerr.find_first_of(
':',c1+1);
773 std::string line = lerr.substr(c1+1,c2-c1-1);
775 lerr=
"error in Lua script: line " + line +
": " + lerr.substr(c2+2);
778 throw Exception(
"LuaFunction::DoExecuteA()", lerr, 49);
782 int errrun=lua_pcall(
pLL, 0, 0, 0);
784 std::stringstream errstr;
785 errstr <<
"failed to run script: ";
786 errstr << std::string(lua_tostring(
pLL, -1));
788 throw Exception(
"LuaFunction::DoExecuteA()", errstr.str(), 49);
795 FD_DLB(
"LuaFunction::DoExecuteB()");
798 lua_getglobal(
pLL,
"faudes");
800 if(!lua_istable(
pLL,-1)) {
802 throw Exception(
"LuaFunction::DoExecuteB()",
"failed to load faudes table", 49);
807 lua_pushstring(
pLL,fname.c_str());
809 if(!lua_isfunction(
pLL,-1)) {
811 lua_getglobal(
pLL,fname.c_str());
812 if(!lua_isfunction(
pLL,-1)) {
813 std::stringstream errstr;
814 errstr <<
"missing function \"" << fname <<
"\"";
816 throw Exception(
"LuaFunction::DoExecuteB()", errstr.str(), 49);
821 lua_pushstring(
pLL,
"Type");
823 if(!lua_isfunction(
pLL,-1))
824 if(!lua_istable(
pLL,-1)) {
826 throw Exception(
"LuaFunction::DoExecuteB():",
"failed to construct plain Type (1)", 49);
829 if(lua_pcall(
pLL, 0, 1, 0) != 0) {
831 throw Exception(
"LuaFunction::DoExecuteB():",
"failed to construct plain Type (2)", 49);
834 swig_lua_userdata* susr = (swig_lua_userdata*) lua_touserdata (
pLL, -1);
837 throw Exception(
"LuaFunction::DoExecuteB():",
"failed to construct plain Type (3)", 49);
839 FD_DLB(
"LuaFunction::DoExecuteB(): plain type is " << susr->type->name);
850 FD_DLB(
"LuaFunction::DoExecuteC()");
864 if((ftype==
"Integer") || (ftype==
"Boolean") || (ftype==
"String")) {
894 FD_DLB(
"LuaFunction::DoExecuteC(): skip nonparameter value pos " << i);
898 if(ftype==
"Integer") {
900 FD_DLB(
"LuaFunction::DoExecuteC(): created ftype " << ftype);
904 if(ftype==
"Boolean") {
906 FD_DLB(
"LuaFunction::DoExecuteC(): created ftype " << ftype);
910 if(ftype==
"String") {
911 lua_pushstring(
pLL,((String*)
ParamValue(i))->CValue().c_str());
912 FD_DLB(
"LuaFunction::DoExecuteC(): created ftype " << ftype);
916 lua_pushstring(
pLL,ftype.c_str());
918 if(!lua_isfunction(
pLL,-1))
919 if(!lua_istable(
pLL,-1)) {
920 std::stringstream errstr;
921 errstr <<
"failed to load constructor for \"" << ftype <<
"\"";
923 throw Exception(
"LuaFunction::DoExecuteC()", errstr.str(), 49);
926 if(lua_pcall(
pLL, 0, 1, 0) != 0) {
927 std::stringstream errstr;
928 errstr <<
"failed to construct for \"" << ftype <<
"\" (1)";
930 throw Exception(
"LuaFunction::DoExecuteC()", errstr.str(), 49);
933 swig_lua_userdata* susr = (swig_lua_userdata*) lua_touserdata (
pLL, -1);
935 std::stringstream errstr;
936 errstr <<
"failed to construct for\"" << ftype <<
"\" (2)";
938 throw Exception(
"LuaFunction::DoExecuteB()", errstr.str(), 49);
941 FD_DLB(
"LuaFunction::DoExecuteC(): created stype " << susr->type->name <<
" for ftype " << ftype);
943 FD_DLB(
"LuaFunction::DoExecuteC(): swig usrdata ptr " << susr->ptr);
944 FD_DLB(
"LuaFunction::DoExecuteC(): swig usrdata own flag " << susr->own);
955 if(susr->own) free(susr->ptr);
957 susr->ptr =
dynamic_cast<void*
>(
ParamValue(i));
960 FD_DLB(
"LuaFunction::DoExecuteC(): done");
965 FD_DLB(
"LuaFunction::DoExecuteD()");
971 int t2=lua_gettop(
pLL);
972 for(
int i= t1; i<=t2; i++) {
973 lua_pushvalue(
pLL,i);
974 #ifdef FAUDES_DEBUG_LUABINDINGS
976 swig_lua_userdata* susr = (swig_lua_userdata*) lua_touserdata (
pLL, -1);
979 FD_DLB(
"LuaFunction::DoExecuteD(): inspect stype " << susr->type->name);
980 FD_DLB(
"LuaFunction::DoExecuteD(): swig usrdata ptr " << susr->ptr);
981 FD_DLB(
"LuaFunction::DoExecuteD(): swig usrdata own flag " << susr->own);
983 FD_DLB(
"LuaFunction::DoExecuteD(): faudes::Type converted ptr " << fptr);
989 FD_DLB(
"LuaFunction::DoExecuteD(): detect error");
990 std::string lerr= std::string(lua_tostring(
pLL, -1));
992 if(lerr.find(
"break on application request")!=std::string::npos) {
993 lerr=
"break on application request";
996 else if(lerr.find(
"luafaudes script:")!=std::string::npos) {
997 std::size_t c1=lerr.find(
"luafaudes script:");
998 lerr=lerr.substr(c1);
1001 else if(lerr.size()>=2) {
1002 std::size_t c1 = lerr.find_first_of(
':');
1003 if(c1==std::string::npos) c1=0;
1004 if(c1+1>=lerr.size()) c1=0;
1005 std::size_t c2 = lerr.find_first_of(
':',c1+1);
1006 if(c2==std::string::npos) c2=c1+1;
1008 std::string line = lerr.substr(c1+1,c2-c1-1);
1009 lerr=
"error in Lua script: line " + line +
": " + lerr.substr(c2+2);
1014 throw Exception(
"LuaFunction::DoExecuteD()", lerr, 49);
1016 FD_DLB(
"LuaFunction::DoExecuteD():done ");
1022 FD_DLB(
"LuaFunction::DoExecuteE()");
1025 for(
int i=
Variant()->Size()-1; i>=0; i--) {
1031 if(ftype==
"Integer" && lua_isnumber(
pLL,-1)) {
1032 FD_DLB(
"LuaFunction::DoExecuteE(): retrieve type " << ftype);
1038 if(ftype==
"Boolean" && lua_isboolean(
pLL,-1)) {
1040 FD_DLB(
"LuaFunction::DoExecuteE(): retrieved type " << ftype);
1045 if(ftype==
"String" && lua_isstring(
pLL,-1)) {
1047 FD_DLB(
"LuaFunction::DoExecuteE(): retrieved type " << ftype);
1052 std::stringstream errstr;
1053 errstr <<
"invalid return values in \"" <<
Variant()->
Name() <<
"\"";
1055 throw Exception(
"LuaFunction::DoExecuteE()", errstr.str(), 49);
1103 for(
int i=
Variant()->Size()-1; i>=0; i--) {
1143 const LuaFunctionDefinition* lfd=
dynamic_cast<const LuaFunctionDefinition*
>(fit->second);
1164 FD_DLB(
"LuaState::Open()");
1169 FD_DLB(
"LuaState::Done()");
1175 FD_DLB(
"LuaState::Close()");
1182 lua_gc(pLL, LUA_GCSTOP, 0);
1184 luaopen_faudes_allplugins(pLL);
1185 lua_gc(pLL, LUA_GCRESTART, 0);
1192 FD_DLB(
"LuaState::Insatll(): file " << rFilename);
1193 TokenReader tr(rFilename);
1195 while(tr.Peek(token)) {
1197 if(!token.IsBegin(
"LuaFunctionDefinition")) {
1201 LuaFunctionDefinition lfd;
1203 FD_DLB(
"LuaState::Install(): found " << lfd.Name());
1215 FD_DLB(
"LuaFunction::Push()");
1216 int savetop=lua_gettop(pLL);
1219 lua_getglobal(pLL,
"faudes");
1220 int ftable=lua_gettop(pLL);
1221 if(!lua_istable(pLL,-1)) {
1222 lua_settop(pLL,savetop);
1223 throw Exception(
"LuaState::Push()",
"failed to load faudes table", 49);
1226 lua_pushstring(pLL,
"Type");
1227 lua_gettable(pLL,ftable);
1228 if(!lua_isfunction(pLL,-1))
1229 if(!lua_istable(pLL,-1)) {
1230 lua_settop(pLL,savetop);
1231 throw Exception(
"LuaState::Push()",
"failed to construct plain Type (1)", 49);
1234 if(lua_pcall(pLL, 0, 1, 0) != 0) {
1235 lua_settop(pLL,savetop);
1236 throw Exception(
"LuaState::Push()",
"failed to construct plain Type (2)", 49);
1239 swig_lua_userdata* susr = (swig_lua_userdata*) lua_touserdata (pLL, -1);
1241 lua_settop(pLL,savetop);
1242 throw Exception(
"LuaState::Push()",
"failed to construct plain Type (3)", 49);
1244 FD_DLB(
"LuaState::Push(): plain type is " << susr->type->name);
1252 if(ftype==
"Integer") {
1253 lua_pushnumber(pLL,((
const Integer&)*fdata));
1254 FD_DLB(
"LuaState::Push(): created ftype " << ftype);
1257 else if(ftype==
"Boolean") {
1258 lua_pushboolean(pLL,((
const Boolean&)*fdata));
1259 FD_DLB(
"LuaState::Push(): created ftype " << ftype);
1262 else if(ftype==
"String") {
1263 lua_pushstring(pLL,((
const String&)*fdata).CValue().c_str());
1264 FD_DLB(
"LuaState::Push(): created ftype " << ftype);
1269 lua_pushstring(pLL,ftype.c_str());
1270 lua_gettable(pLL,ftable);
1271 if(!lua_isfunction(pLL,-1))
1272 if(!lua_istable(pLL,-1)) {
1273 std::stringstream errstr;
1274 errstr <<
"failed to load constructor for \"" << ftype <<
"\"";
1275 lua_settop(pLL,savetop);
1276 throw Exception(
"LuaState::Push()", errstr.str(), 49);
1279 if(lua_pcall(pLL, 0, 1, 0) != 0) {
1280 std::stringstream errstr;
1281 errstr <<
"failed to construct for \"" << ftype <<
"\" (1)";
1282 lua_settop(pLL,savetop);
1283 throw Exception(
"LuaState::Push()", errstr.str(), 49);
1286 swig_lua_userdata* susr = (swig_lua_userdata*) lua_touserdata (pLL, -1);
1288 std::stringstream errstr;
1289 errstr <<
"failed to construct for\"" << ftype <<
"\" (2)";
1290 lua_settop(pLL,savetop);
1291 throw Exception(
"LuaState::Push()", errstr.str(), 49);
1294 FD_DLB(
"LuaState::Push(): created stype " << susr->type->name <<
" for ftype " << ftype);
1295 FD_DLB(
"LuaState::Push(): faudes parameter at " << fdata);
1296 FD_DLB(
"LuaState::Push(): swig usrdata ptr " << susr->ptr);
1297 FD_DLB(
"LuaState::Push(): swig usrdata own flag " << susr->own);
1299 void* fptr=
SwigCastPtr(susr->ptr,susr->type,stype);
1300 FD_DLB(
"LuaState::Push(): faudes plain Type converted ptr " << fptr);
1302 std::stringstream errstr;
1303 errstr <<
"failed cast from " << ftype;
1304 lua_settop(pLL,savetop);
1305 throw Exception(
"LuaState::Push()", errstr.str(), 49);
1307 ((Type*)fptr)->Assign(*fdata);
1310 lua_replace(pLL,-2);
1311 FD_DLB(
"LuaFunction::DoExecuteB(): done");
1321 FD_DLB(
"LuaFunction::Pop()");
1322 int savetop=lua_gettop(pLL);
1326 if(lua_isnumber(pLL,-1)) {
1327 res=
new Integer(lua_tointeger(pLL,-1));
1332 if(lua_isstring(pLL,-1)) {
1333 res=
new String(lua_tostring(pLL,-1));
1338 if(lua_isboolean(pLL,-1)) {
1339 res=
new Boolean(lua_toboolean(pLL,-1));
1345 lua_getglobal(pLL,
"faudes");
1346 int ftable=lua_gettop(pLL);
1347 if(!lua_istable(pLL,-1)) {
1348 lua_settop(pLL,savetop);
1349 throw Exception(
"LuaState::Pop()",
"failed to load faudes table", 49);
1353 lua_pushstring(pLL,
"Type");
1354 lua_gettable(pLL,ftable);
1355 if(!lua_isfunction(pLL,-1))
1356 if(!lua_istable(pLL,-1)) {
1357 lua_settop(pLL,savetop);
1358 throw Exception(
"LuaState::Pop()",
"failed to construct plain Type (1)", 49);
1361 if(lua_pcall(pLL, 0, 1, 0) != 0) {
1362 lua_settop(pLL,savetop);
1363 throw Exception(
"LuaState::Pop()",
"failed to construct plain Type (2)", 49);
1366 swig_lua_userdata* susr = (swig_lua_userdata*) lua_touserdata (pLL, -1);
1368 lua_settop(pLL,savetop);
1369 throw Exception(
"LuaState::Pop()",
"failed to construct plain Type (3)", 49);
1371 FD_DLB(
"LuaState::Pop(): plain type is " << susr->type->name);
1379 std::stringstream errstr;
1380 errstr <<
"unknown data type";
1381 lua_settop(pLL,savetop);
1382 throw Exception(
"LuaState::Pop()", errstr.str(), 49);
1385 void* fptr=
SwigCastPtr(susr->ptr,susr->type,stype);
1386 FD_DLB(
"LuaState::Pop(): swig usrdata ptr " << susr->ptr);
1387 FD_DLB(
"LuaState::Pop(): swig stype " << susr->type->name);
1388 FD_DLB(
"LuaState::Pop(): faudes::Type converted ptr " << fptr);
1390 std::stringstream errstr;
1391 errstr <<
"faild to cast stype \"" << susr->type->name <<
"\" to plain Type";
1392 lua_settop(pLL,savetop);
1393 throw Exception(
"LuaState::Pop()", errstr.str(), 49);
1396 res=((Type*)fptr)->Copy();
1399 FD_DLB(
"LuaFunction::Pop(): done");
1409 Type*
LuaState::Global(lua_State* pLL,
const std::string& gname,
const Type* fdata) {
1412 lua_getfield(pLL, LUA_GLOBALSINDEX, gname.c_str());
1418 lua_setfield(pLL, LUA_GLOBALSINDEX, gname.c_str());
1431 FD_DLB(
"LuaFunction::Evaluate()");
1434 int top = lua_gettop(pLL);
1439 if(luaL_loadbuffer(pLL, expr.c_str(), expr.size(),
"string")) {
1440 cerr=std::string(lua_tostring(pLL, -1));
1446 if(lua_pcall(pLL, 0, LUA_MULTRET, 0)){
1447 cerr=std::string(lua_tostring(pLL, -1));
1452 lua_settop(pLL,top);
1453 lua_gc(pLL, LUA_GCCOLLECT, 0);
1457 lua_settop(pLL,top);
1458 throw Exception(
"LuaState::Evaluate()", cerr, 49);
1471 std::list< std::string >
LuaState::Complete(lua_State* pLL,
const std::string& word) {
1472 FD_DLB(
"LuaFunction::Complete(" << word <<
")");
#define FD_WARN(message)
Debug: always report warnings.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
const std::string & Name(void) const
Get name of the entety to document (aka faudes-type or faudes-function).
std::string KeywordAt(int pos) const
const std::string & PlugIn(void) const
Get name of plugin.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data of this object to TokenWriter.
const std::string & TextDoc(void) const
const std::string & CType(void) const
Get corresponding C++ type.
std::string mName
Faudes name.
std::string mPlugIn
Faudes plugin.
virtual const char * What() const
Returns error description.
A FunctionDefinition defines the interface to a faudes-function.
const Signature & Variant(const std::string &rName) const
Return reference to Signature by name.
void DoAssign(const FunctionDefinition &rSrc)
Std faudes type interface: assignment.
int VariantsSize(void) const
Return number of supported Signature instances.
const Function * Prototype(void) const
Return pointer to function object prototype.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read configuration data of this object from TokenReader.
virtual void DoReadCore(TokenReader &rTr)
Read configuration data of this object from TokenReader.
bool DoEqual(const FunctionDefinition &rOther) const
Std faudes type interface: test equality.
virtual void DoWriteCore(TokenWriter &rTw) const
Write configuration data of this object to TokenWriter.
Function * mpFunction
Prototype instance.
virtual void Clear(void)
Clear documentation-data and signature (keep prototype)
Iterator End(void) const
STL interator to the internal function-name map.
static FunctionRegistry * G()
Method to access the single global instance of the registry.
std::map< std::string, FunctionDefinition * >::const_iterator Iterator
Convenience typedef to access registry entries.
void Insert(FunctionDefinition *pFunctionDef)
Add another function definition to the registry.
Iterator Begin(void) const
STL interator to the internal function-name map.
A faudes-function hosts parameter values of some faudes type and provides a method to perform an oper...
virtual void Definition(const FunctionDefinition *fdef)
Set function definition.
void Variant(int n)
Set signature from function definition.
const Signature * Variant(void) const
Return pointer to assigned faudes::Signature.
const FunctionDefinition * Definition(void) const
Get function definition.
void FreeValues(void)
Destruct parameter values.
void AllocateValues(void)
Construct parameter values.
virtual void DoVariant(int n)
std::vector< Type * > mParameterValues
Vector of arguments.
void ParamValue(int n, Type *param)
Set parameter at certain position.
int mVariantIndex
current variant aka signature as index w.r.t.
int VariantsSize(void) const
Return number of variants.
A LuaFunctionDefinition is derived from FunctionDefinition to define a faudes-function by a Lua scrip...
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read configuration data of this object from TokenReader.
virtual void DoWriteCore(TokenWriter &rTw) const
Write configuration data of this object to TokenWriter.
void Install(LuaState *pL=NULL) const
Install this function to a Lua state.
LuaState * pDefaultL
Default lua state.
std::string SyntaxCheck(void)
Syntax check lua code.
virtual void DoReadCore(TokenReader &rTr)
Read configuration data of this object from TokenReader.
std::string mLuaFile
Lua file.
LuaState * DefaultL(void) const
Get default lua state.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data of this object to TokenWriter.
LuaFunction * pLuaFunction
Typed prototype instance.
std::string Evaluate(LuaState *pL=NULL)
Evaluate lua code.
void DefaultL(LuaState *pL)
Set default lua state.
LuaFunctionDefinition(const std::string &name="")
Constructor.
std::string mLuaCode
Lua code.
void Clear(void)
Clear documentation-data, signature and script (keep prototype)
static void Register(const std::string &rFilename)
const std::string & LuaCode(void) const
Get Lua code.
virtual bool DoEqual(const LuaFunctionDefinition &rOther) const
Std faudes type interface: test equality.
virtual void DoAssign(const LuaFunctionDefinition &rSrc)
Std faudes type interface: assignment.
A LuaFunction is a faudes-function that executes a luafaudes script.
LuaState * L(void)
Get default lua state.
virtual void DoExecuteC()
Execute stages.
std::vector< bool > mLParameter
void SyntaxCheck(void)
Syntax check lua code.
virtual void DoExecuteB()
Execute stages.
void L(LuaState *l)
Set lua state.
virtual void DoExecuteD()
Execute stages.
LuaState * pL
State of Lua interpreter.
virtual void DoExecute()
Executes code as supplied by FunctionDefinition.
LuaFunction(const LuaFunctionDefinition *fdef)
Constructor.
virtual void DoExecuteE()
Execute stages.
void Evaluate(void)
Evaluate lua code.
virtual bool DoTypeCheck(int n)
Method to test the type of an assigned parameter with the specified faudes::Signature (i....
virtual LuaFunction * New() const
Construct on heap.
const LuaFunctionDefinition * pLuaFuncDef
Typed reference to definition.
std::vector< bool > mLReturn
virtual void DoVariant(int n)
const LuaFunctionDefinition * Definition(void) const
Get function definition.
virtual void DoExecuteA()
Execute stages.
Wrapper class to maintain a Lua state.
static void Initialize(lua_State *pLL)
Initialze.
Type * Global(const std::string &gname, const Type *fdata=0)
Get/set global data.
Type * Pop(void)
Pop faudes typed object from Lua stack.
static LuaState * G(void)
Convenience global Lua state.
void Install(const std::string &rFilename)
Install LuaExtension to Lua state.
void Evaluate(const std::string &expr)
Evaluate Lua expression.
void Reset(void)
Reinitialize Lua state.
lua_State * LL(void)
Access Lua state.
std::list< std::string > Complete(const std::string &word)
Complete Lua identifier.
void Push(const Type *fdata)
Push faudes typed object on the Lua stack.
LuaState(void)
Constructor.
~LuaState(void)
Destructor.
std::string Str(void) const
Convenience method to produce a textual representation of a parameter.
bool CReturn(void) const
Get C-Return flag.
ParamAttr
A function parameter has has one out of four so called io-attrributes;.
const std::string & Type(void) const
Get type.
const ParamAttr & Attribute(void) const
Get Attribute.
int Size(void) const
Return number of parameters.
const std::string & Name(void) const
Return signature name.
const Parameter & At(int n) const
Get parameter type by position.
A TokenReader reads sequential tokens from a file or string.
const Type * Prototype(const std::string &rTypeName) const
Look up the prototype object by faudes-type name.
static TypeRegistry * G()
Method to access the single global instance of the registry.
Base class of all libFAUDES objects that participate in the run-time interface.
virtual const std::string & Name(void) const
Get objects's name.
const std::string & FaudesTypeName(const Type &rObject)
Query type name.
static std::list< std::string > faudes_rl_complete(lua_State *L, const std::string &word)
luafaudes class to run scripts as rti functions
Includes all luabindings plug-in headers.
libFAUDES resides within the namespace faudes.
struct faudes::swig_type_info swig_type_info
struct swig_type_info *(* swig_dycast_func)(void **)
void * SwigCastPtr(void *ptr, swig_type_info *from, swig_type_info *ty)
void faudes_hook_register(lua_State *L)
struct faudes::swig_cast_info swig_cast_info
swig_lua_userdata * SwigUserData(lua_State *L, int index)
FAUDES_API void faudes_dict_insert_entry(const std::string &topic, const std::string &key, const std::string &entry)
std::string ToStringInteger(Int number)
integer to string
void faudes_print_register(lua_State *L)
void *(* swig_converter_func)(void *, int *)
std::string MangleString(const std::string &str)
swig_converter_func converter
struct swig_cast_info * prev
struct swig_cast_info * next
struct swig_cast_info * cast