Jump to content
  • Advertisement
Sign in to follow this  
orcfan32

VB.NET 2005, scripting languages - [RESOLVED]

This topic is 4359 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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++...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!