fix(gbdialog): VBA hear must be a wrapper call.
This commit is contained in:
parent
776fe03503
commit
6915d58db1
3 changed files with 100 additions and 9 deletions
|
@ -102,7 +102,7 @@ export class GBVMService implements IGBCoreService {
|
|||
// Convert TS into JS.
|
||||
const tsfile = `bot.ts`;
|
||||
const tsc = new TSCompiler();
|
||||
// TODO: tsc.compile([UrlJoin(path, tsfile)]);
|
||||
tsc.compile([UrlJoin(path, tsfile)]);
|
||||
// Run JS into the GB context.
|
||||
const jsfile = `bot.js`;
|
||||
localPath = UrlJoin(path, jsfile);
|
||||
|
@ -112,8 +112,24 @@ export class GBVMService implements IGBCoreService {
|
|||
code = code.replace(/^.*exports.*$/gm, '');
|
||||
code = code.replace(/this\./gm, 'await this.');
|
||||
code = code.replace(/function/gm, 'async function');
|
||||
var match;
|
||||
let finalCode: string;
|
||||
let pos = 0;
|
||||
while ((match = /hear.*\(\)/.exec(code)) != null) {
|
||||
pos = match.index;
|
||||
console.log(pos);
|
||||
finalCode += code.substring(0, pos);
|
||||
let nextCode = code.substring(pos);
|
||||
|
||||
// Find last }
|
||||
|
||||
while ((match = /\{|\}/g.exec(nextCode)) != null) {
|
||||
console.log(match.index);
|
||||
}
|
||||
}
|
||||
|
||||
//code = code.replace(/this\.hear\(\){/gm, 'this.hear(async () => { ');
|
||||
|
||||
|
||||
const sandbox: DialogClass = new DialogClass(min);
|
||||
const context = vm.createContext(sandbox);
|
||||
vm.runInContext(code, context);
|
||||
|
@ -122,4 +138,60 @@ export class GBVMService implements IGBCoreService {
|
|||
logger.info(`[GBVMService] Finished loading of ${filename}`);
|
||||
}
|
||||
}
|
||||
|
||||
public static async run2(source: any, path: string) {
|
||||
// Converts VBS into TS.
|
||||
|
||||
//vb2ts.convertFile(source);
|
||||
|
||||
// Convert TS into JS.
|
||||
const tsfile = `bot.ts`;
|
||||
const tsc = new TSCompiler();
|
||||
//tsc.compile([UrlJoin(path, tsfile)]);
|
||||
// Run JS into the GB context.
|
||||
const jsfile = `bot.js`;
|
||||
let localPath = UrlJoin(path, jsfile);
|
||||
|
||||
if (fs.existsSync(localPath)) {
|
||||
let code: string = fs.readFileSync(localPath, 'utf8');
|
||||
code = code.replace(/^.*exports.*$/gm, '');
|
||||
code = code.replace(/this\./gm, 'await this.');
|
||||
code = code.replace(/function/gm, 'async function');
|
||||
var match1;
|
||||
var match2;
|
||||
let finalCode: string;
|
||||
let pos = 0;
|
||||
while ((match1 = /hear.*\(\)/.exec(code))) {
|
||||
pos = match1.index;
|
||||
console.log(pos);
|
||||
finalCode += code.substring(0, pos);
|
||||
let nextCode = code.substring(pos);
|
||||
|
||||
// Find last }
|
||||
let right = 0;
|
||||
let left = 1;
|
||||
|
||||
while ((match2 = /\{|\}/.exec(nextCode))) {
|
||||
let c = nextCode.substring(match2.index, match2.index+1);
|
||||
if (c === '}') {
|
||||
right++;
|
||||
} else if (c === '{') {
|
||||
left++;
|
||||
}
|
||||
|
||||
nextCode = nextCode.substring(match2.index + 1);
|
||||
|
||||
if (left == right)
|
||||
{
|
||||
console.log('end '+match2.index);
|
||||
}
|
||||
console.log(match2.index);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(finalCode);
|
||||
|
||||
//code = code.replace(/this\.hear\(\){/gm, 'this.hear(async () => { ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,23 @@
|
|||
'
|
||||
'****************************************************************************
|
||||
|
||||
this.talk ("Please, what's your e-mail address?")
|
||||
let email = this.hear()
|
||||
this.talk("Thanks, sending e-mail to: " + email);
|
||||
this.sendEmail(email, "Message from VBA Bot", "Yes, I can send e-mails.");
|
||||
%>
|
||||
talk ("Please, what's your e-mail address?")
|
||||
email = hear ()
|
||||
talk("Thanks, sending e-mail to: " + email )
|
||||
sendEmail(email, "Message from VBA Bot", "Yes, I can send e-mails.")
|
||||
if email = "" then
|
||||
|
||||
end if
|
||||
|
||||
select case email
|
||||
case 1:
|
||||
|
||||
case 2:
|
||||
|
||||
end select
|
||||
|
||||
if i > 10 then
|
||||
|
||||
end if
|
||||
|
||||
%>
|
|
@ -50,6 +50,7 @@ import { GBCoreService } from '../packages/core.gbapp/services/GBCoreService';
|
|||
import { GBDeployer } from '../packages/core.gbapp/services/GBDeployer';
|
||||
import { GBImporter } from '../packages/core.gbapp/services/GBImporterService';
|
||||
import { GBMinService } from '../packages/core.gbapp/services/GBMinService';
|
||||
import { GBVMService } from '../packages/core.gbapp/services/GBVMService';
|
||||
|
||||
const appPackages = new Array<IGBPackage>();
|
||||
|
||||
|
@ -150,5 +151,8 @@ export class GBServer {
|
|||
}
|
||||
|
||||
// First line to run.
|
||||
|
||||
GBServer.run();
|
||||
const path = 'packages/default.gbdialog';
|
||||
const file = 'bot.vbs';
|
||||
const source =(path + '/' + file);
|
||||
GBVMService.run2(source, path)
|
||||
//GBServer.run();
|
||||
|
|
Loading…
Add table
Reference in a new issue