Skip to content

Commit

Permalink
patch ruby $0 to be __FILE__
Browse files Browse the repository at this point in the history
  • Loading branch information
hatemhosny committed Oct 18, 2023
1 parent 309ffb7 commit 5caa158
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/livecodes/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,6 @@ const loadConfig = async (

// load config
await bootstrap(true);

await applyConfig(config);

changingContent = false;
Expand Down Expand Up @@ -3740,29 +3739,30 @@ const configureToolsPane = (
tools: Config['tools'] | undefined,
mode: Config['mode'] | undefined,
) => {
if (!toolsPane) return;
if (mode === 'result' && (!tools || tools.status === '' || tools.status === 'none')) {
toolsPane?.hide();
toolsPane.hide();
return;
}
if (tools?.active) {
toolsPane?.setActiveTool(tools.active);
toolsPane.setActiveTool(tools.active);
}
if (!tools) {
toolsPane?.close();
toolsPane.close();
return;
}
if (tools.status === 'none') {
toolsPane?.hide();
toolsPane.hide();
return;
}
if (tools.status === 'full') {
toolsPane?.maximize();
toolsPane.maximize();
}
if (tools.status === 'open') {
toolsPane?.open();
toolsPane.open();
}
if (tools.status === 'closed' || tools.status === '') {
toolsPane?.close();
toolsPane.close();
}
// TODO: handle tools.enabled
};
Expand Down
3 changes: 2 additions & 1 deletion src/livecodes/languages/ruby-wasm/lang-ruby-wasm-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ livecodes.rubyWasm.run =
await init(hasImports(code));
const { DefaultRubyVM } = (window as any)['ruby-wasm-wasi'];
const { vm } = await DefaultRubyVM(livecodes.rubyWasm.module);
vm.eval(code);
const patch = code.includes('$0') ? '$0 = __FILE__\\n' : '';
vm.eval(patch + code);
parent.postMessage({ type: 'loading', payload: false }, '*');
});

Expand Down
3 changes: 2 additions & 1 deletion src/livecodes/languages/ruby/lang-ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const ruby: LanguageSpecs = {
'ruby',
config,
);
return (self as any).Opal.compile(code, options);
const patch = code.includes('$0') ? '$0 = __FILE__\\n' : '';
return (self as any).Opal.compile(patch + code, options);
};
},
scripts: ({ compiled, config }) => {
Expand Down

0 comments on commit 5caa158

Please sign in to comment.