VB.NET 2005, scripting languages - [RESOLVED]

Started by
6 comments, last by nolongerhere 17 years, 8 months ago
I'm currently looking for a scripting language to implement into VB8. A while back, I recall reading somewhere about Lua becoming a .net language; however, I can no longer find it (Google, CodeProject were places I looked). Does anyone know a link to it and/or know if it's compatible with VB8? I'm looking to allow the end user to write plugins for my app. So if there's a better alternative, please suggest it (Except for Codedom [sick]). [Edited by - orcfan32 on August 10, 2006 9:26:35 AM]
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
Advertisement
How about VB.NET? Or C#?

Look in the Microsoft.CSharp, Microsoft.VisualBasic, and System.CodeDom.Compiler namespaces. You can compile .NET code at runtime, perfect for scripting.

EDIT: OH.. LOL... I just saw the last line. DOn't know how I missed it. What's wrong with CodeDom?

Here:
namespace Core{        public interface IScript    {                   /**          * Executes a script and returns an object of arbitrary type.         */        object execute(object obj);    }    public class ScriptingSystem    {        public static IScript loadScript(String scriptFile)        {            return loadScript(scriptFile, new String [] {});        }        public static IScript loadScript(String scriptFile, String [] references)        {                       try            {                  // Create compiler                CSharpCodeProvider codeProv = new CSharpCodeProvider();                                                CompilerParameters compilerParams = new CompilerParameters();                compilerParams.ReferencedAssemblies.Add("System.dll");                compilerParams.ReferencedAssemblies.Add("Core.dll");                compilerParams.ReferencedAssemblies.AddRange(references);                compilerParams.ReferencedAssemblies.AddRange(parseReferencesFromSource(scriptFile));                compilerParams.GenerateInMemory = true;                CompilerResults results = null;                                results = codeProv.CompileAssemblyFromFile(compilerParams, scriptFile);                                if (results.Errors.Count > 0)                {                    foreach (CompilerError err in results.Errors)                    {                        Console.WriteLine(err);                    }                    return null;                }                IScript result = (IScript)results.CompiledAssembly.CreateInstance("ScriptImpl");                return result;            }            catch (Exception e)             {                Console.WriteLine("EXCEPTION: " + e.Message);                return null;            }                    }        private static String[] parseReferencesFromSource(String sourceFile)        {            StreamReader rdr = new StreamReader(sourceFile);            List<String> list = new List<String>();            Regex regEx = new Regex("//\\s*referenceassembly:");            String line = rdr.ReadLine();                        while (regEx.IsMatch(line.ToLower()))            {                list.Add(line.Split(':')[1].Trim());                line = rdr.ReadLine();            }            rdr.Close();            return list.ToArray();        }    }}


You can implement individual scripts named ScriptImpl. Then it's just a matter of doing something like this:

Script scr = ScriptingSystem.loadScript("testscript1.cs");retVal = scr.execute(someObj); 


I know that isn't what you wanted, but I had it so... whatever.


Reason I don't like Codedom is because the end user will have almost as much access as the language itself, meaning they could easily write a virus in the form of a plugin.
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
Have a look at Boo.
Already have. I don't like the fact that it's typed, and I don't know a thing about the python syntax.
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
That its typed? Isnt the MSIL typed...?
As a scripting language I want it to be easy to use. Instead of having the user to memorize different data types, they should only have to go
a = "string"

then a second later
a = 12345


It's no different than Lua in C++...
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
Lua is interpretted, not compiled.

BTW, Boo does have duck typing last time I checked.

This topic is closed to new replies.

Advertisement