mirror of
https://github.com/opensim/opensim.git
synced 2026-07-31 22:05:36 +08:00
Adds a new script command 'modInvoke' to invoke registered functions
from region modules. The LSL translator is extended to generate the
modInvoke format of commands for directly inlined function calls.
A region module can register a function Test() with the name "Test".
LSL code can call that function as "Test()". The compiler will translate
that invocation into modInvoke("Test", ...)
This commit is contained in:
@@ -32,6 +32,8 @@ using System.Reflection;
|
||||
using log4net;
|
||||
using Tools;
|
||||
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
{
|
||||
public class CSCodeGenerator : ICodeConverter
|
||||
@@ -45,12 +47,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
private int m_CSharpLine; // the current line of generated C# code
|
||||
private int m_CSharpCol; // the current column of generated C# code
|
||||
private List<string> m_warnings = new List<string>();
|
||||
private IScriptModuleComms m_comms = null;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an 'empty' CSCodeGenerator instance.
|
||||
/// </summary>
|
||||
public CSCodeGenerator()
|
||||
{
|
||||
m_comms = null;
|
||||
ResetCounters();
|
||||
}
|
||||
|
||||
public CSCodeGenerator(IScriptModuleComms comms)
|
||||
{
|
||||
m_comms = comms;
|
||||
ResetCounters();
|
||||
}
|
||||
|
||||
@@ -866,8 +876,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
{
|
||||
string retstr = String.Empty;
|
||||
|
||||
retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc);
|
||||
|
||||
string modinvoke = m_comms.LookupModInvocation(fc.Id);
|
||||
if (modinvoke != null)
|
||||
{
|
||||
if (fc.kids[0] is ArgumentList)
|
||||
{
|
||||
if ((fc.kids[0] as ArgumentList).kids.Count == 0)
|
||||
retstr += Generate(String.Format("{0}(\"{1}\"",modinvoke,fc.Id), fc);
|
||||
else
|
||||
retstr += Generate(String.Format("{0}(\"{1}\",",modinvoke,fc.Id), fc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc);
|
||||
}
|
||||
|
||||
foreach (SYMBOL kid in fc.kids)
|
||||
retstr += GenerateNode(kid);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ using Microsoft.CSharp;
|
||||
//using Microsoft.JScript;
|
||||
using Microsoft.VisualBasic;
|
||||
using log4net;
|
||||
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.ScriptEngine.Interfaces;
|
||||
using OpenMetaverse;
|
||||
@@ -293,6 +294,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
{
|
||||
// m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script);
|
||||
|
||||
IScriptModuleComms comms = m_scriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
|
||||
|
||||
linemap = null;
|
||||
m_warnings.Clear();
|
||||
|
||||
@@ -382,7 +385,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
if (language == enumCompileType.lsl)
|
||||
{
|
||||
// Its LSL, convert it to C#
|
||||
LSL_Converter = (ICodeConverter)new CSCodeGenerator();
|
||||
LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms);
|
||||
compileScript = LSL_Converter.Convert(Script);
|
||||
|
||||
// copy converter warnings into our warnings.
|
||||
|
||||
Reference in New Issue
Block a user