[Opalvoip-svn] SF.net SVN: opalvoip:[34644] ptlib/branches/v2_16/src/ptclib
Brought to you by:
csoutheren,
rjongbloed
From: <rjo...@us...> - 2016-02-24 17:19:13
|
Revision: 34644 http://sourceforge.net/p/opalvoip/code/34644 Author: rjongbloed Date: 2016-02-24 17:19:11 +0000 (Wed, 24 Feb 2016) Log Message: ----------- Fixed PScriptLanguage::CreateCall() and various other minor bugs in scripting code. Also added functions to get the current language name for the PScriptLanguage instance. Modified Paths: -------------- opal/branches/v3_16/samples/server/main.cxx ptlib/branches/v2_16/include/ptclib/jscript.h ptlib/branches/v2_16/include/ptclib/lua.h ptlib/branches/v2_16/include/ptclib/script.h ptlib/branches/v2_16/src/ptclib/jscript.cxx ptlib/branches/v2_16/src/ptclib/lua.cxx ptlib/branches/v2_16/src/ptclib/script.cxx Modified: opal/branches/v3_16/samples/server/main.cxx =================================================================== --- opal/branches/v3_16/samples/server/main.cxx 2016-02-24 15:31:10 UTC (rev 34643) +++ opal/branches/v3_16/samples/server/main.cxx 2016-02-24 17:19:11 UTC (rev 34644) @@ -690,11 +690,8 @@ #endif #if OPAL_SCRIPT - PFactory<PScriptLanguage>::KeyList_T keys = PFactory<PScriptLanguage>::GetKeyList(); - if (!keys.empty()) { - PStringArray languages; - for (PFactory<PScriptLanguage>::KeyList_T::iterator it = keys.begin(); it != keys.end(); ++it) - languages.AppendString(*it); + PStringArray languages = PScriptLanguage::GetLanguages(); + if (!languages.empty()) { PCaselessString language = cfg.GetString(ScriptLanguageKey, languages[0]); rsrc->Add(new PHTTPRadioField(ScriptLanguageKey, languages, languages.GetValuesIndex(language),"Interpreter script language.")); Modified: ptlib/branches/v2_16/include/ptclib/jscript.h =================================================================== --- ptlib/branches/v2_16/include/ptclib/jscript.h 2016-02-24 15:31:10 UTC (rev 34643) +++ ptlib/branches/v2_16/include/ptclib/jscript.h 2016-02-24 17:19:11 UTC (rev 34644) @@ -62,8 +62,14 @@ ~PJavaScript(); //@} - /**@name Path addition functions */ + /**@name Scripting functions */ //@{ + /// Get the name of this scripting language + static PString LanguageName(); + + /// Get the name of this scripting language + virtual PString GetLanguageName() const; + /**Load a JavaScript script from a file. */ virtual bool LoadFile( Modified: ptlib/branches/v2_16/include/ptclib/lua.h =================================================================== --- ptlib/branches/v2_16/include/ptclib/lua.h 2016-02-24 15:31:10 UTC (rev 34643) +++ ptlib/branches/v2_16/include/ptclib/lua.h 2016-02-24 17:19:11 UTC (rev 34644) @@ -71,8 +71,14 @@ ~PLua(); //@} - /**@name Path addition functions */ + /**@name Scripting functions */ //@{ + /// Get the name of this scripting language + static PString LanguageName(); + + /// Get the name of this scripting language + virtual PString GetLanguageName() const; + /**Load a Lua script from a file. */ virtual bool LoadFile( Modified: ptlib/branches/v2_16/include/ptclib/script.h =================================================================== --- ptlib/branches/v2_16/include/ptclib/script.h 2016-02-24 15:31:10 UTC (rev 34643) +++ ptlib/branches/v2_16/include/ptclib/script.h 2016-02-24 17:19:11 UTC (rev 34644) @@ -48,7 +48,14 @@ { PCLASSINFO(PScriptLanguage, PObject) public: - static PScriptLanguage * Create(const PString & language); + static PScriptLanguage * Create(const PString & language) + { + return PFactory<PScriptLanguage>::CreateInstance(language); + } + static PStringList GetLanguages() + { + return PFactory<PScriptLanguage>::GetKeyList(); + } /**@name Construction */ //@{ @@ -60,8 +67,11 @@ ~PScriptLanguage(); //@} - /**@name Path addition functions */ + /**@name Scripting functions */ //@{ + /// Get the name of this scripting language + virtual PString GetLanguageName() const = 0; + /**Load a script from a file. */ virtual bool LoadFile( Modified: ptlib/branches/v2_16/src/ptclib/jscript.cxx =================================================================== --- ptlib/branches/v2_16/src/ptclib/jscript.cxx 2016-02-24 15:31:10 UTC (rev 34643) +++ ptlib/branches/v2_16/src/ptclib/jscript.cxx 2016-02-24 17:19:11 UTC (rev 34644) @@ -75,7 +75,8 @@ #define PTraceModule() "JavaScript" -PFACTORY_CREATE(PFactory<PScriptLanguage>, PJavaScript, "Java", false); +static PConstString const JavaName("Java"); +PFACTORY_CREATE(PFactory<PScriptLanguage>, PJavaScript, JavaName, false); static atomic<bool> V8_initialised; @@ -250,16 +251,16 @@ } - void SetMember(v8::Handle<v8::Object> object, const PString & name, v8::Handle<v8::Value> value) + bool SetMember(v8::Handle<v8::Object> object, const PString & name, v8::Handle<v8::Value> value) { if (m_isolate == NULL) - return; + return false; // set flags if array access if (name[0] == '[') - object->Set(name.Mid(1).AsInteger(), value); + return object->Set(name.Mid(1).AsInteger(), value); else - object->Set(NewString(name), value); + return object->Set(NewString(name), value); } @@ -346,6 +347,12 @@ } + bool NewObject(const PString & name) + { + return false; + } + + bool SetVar(const PString & key, const PVarType & var) { if (m_isolate == NULL) @@ -358,40 +365,34 @@ PStringArray tokens; if (ParseKey(key, tokens) < 1) { - PTRACE(5, "SetVar '" << key << " is too short"); + PTRACE(3, "SetVar \"" << key << "\" is too short"); return false; } v8::Handle<v8::Object> object = context->Global(); - int i = 0; - - while (i > 0) { - + PINDEX i; + for (i = 0; i < tokens.GetSize()-1; ++i) { // get the member variable v8::Handle<v8::Value> value = GetMember(object, tokens[i]); if (value.IsEmpty()) { - PTRACE(5, "Cannot get element '" << tokens[i] << "'"); + PTRACE(3, "Cannot get element \"" << tokens[i] << '"'); return false; } + // if path has ended, return error + object = value->ToObject(); + if (object.IsEmpty()) { + PTRACE(3, "SetVar intermediate element \"" << tokens[i] << "\" not found"); + return false; + } + // terminals must not be composites, internal nodes must be composites bool isObject = value->IsObject(); if (!isObject) { - tokens.SetSize(i + 1); - PTRACE(5, "GetVar intermediate node '" << setfill('.') << tokens << "' is not a composite"); + PTRACE(3, "SetVar intermediate element \"" << tokens[i] << "\" is not a composite"); return false; } - - // if path has ended, return error - object = value->ToObject(); - if (object->IsNull()) { - tokens.SetSize(i + 1); - PTRACE(5, "GetVar intermediate node '" << setfill('.') << tokens << " not found"); - return false; - } - - i++; } v8::Handle<v8::Value> value; @@ -439,11 +440,11 @@ case PVarType::VarStaticBinary: case PVarType::VarDynamicBinary: default: + value = v8::Object::New(m_isolate); break; } - SetMember(object, tokens[i], value); - return true; + return SetMember(object, tokens[i], value); } @@ -502,6 +503,18 @@ } +PString PJavaScript::LanguageName() +{ + return JavaName; +} + + +PString PJavaScript::GetLanguageName() const +{ + return JavaName; +} + + bool PJavaScript::LoadFile(const PFilePath & /*filename*/) { return false; @@ -520,9 +533,11 @@ } -bool PJavaScript::CreateComposite(const PString & /*name*/) +bool PJavaScript::CreateComposite(const PString & name) { - return false; + PVarType dummy; + dummy.SetType(PVarType::VarStaticBinary); + return m_private->SetVar(name, dummy); } Modified: ptlib/branches/v2_16/src/ptclib/lua.cxx =================================================================== --- ptlib/branches/v2_16/src/ptclib/lua.cxx 2016-02-24 15:31:10 UTC (rev 34643) +++ ptlib/branches/v2_16/src/ptclib/lua.cxx 2016-02-24 17:19:11 UTC (rev 34644) @@ -56,7 +56,8 @@ #define PTraceModule() "Lua" -PFACTORY_CREATE(PFactory<PScriptLanguage>, PLua, "Lua", false); +static PConstString const LuaName("Lua"); +PFACTORY_CREATE(PFactory<PScriptLanguage>, PLua, LuaName, false); #define new PNEW @@ -109,6 +110,18 @@ } +PString PLua::LanguageName() +{ + return LuaName; +} + + +PString PLua::GetLanguageName() const +{ + return LuaName; +} + + bool PLua::LoadFile(const PFilePath & filename) { PWaitAndSignal mutex(m_mutex); @@ -612,7 +625,7 @@ if (luaError.IsEmpty()) OnError(code, psprintf("Error code %i", code)); else - OnError(code, str); + OnError(code, luaError); } if (pop > 0) Modified: ptlib/branches/v2_16/src/ptclib/script.cxx =================================================================== --- ptlib/branches/v2_16/src/ptclib/script.cxx 2016-02-24 15:31:10 UTC (rev 34643) +++ ptlib/branches/v2_16/src/ptclib/script.cxx 2016-02-24 17:19:11 UTC (rev 34644) @@ -74,7 +74,7 @@ m_lastErrorText = str; m_mutex.Signal(); - PTRACE(2, GetClass(), "Error " << code << ": " << str); + PTRACE(2, GetLanguageName(), "Error " << code << ": " << str); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |