Added default encoding mode

pull/24/head
Elly2018 8 months ago
parent be4f0fa982
commit 3d5bfd8179

@ -6,5 +6,10 @@
"eslint.validate": [{ "language": "typescript", "autoFix": true }], "eslint.validate": [{ "language": "typescript", "autoFix": true }],
"eslint.autoFixOnSave": true, "eslint.autoFixOnSave": true,
"eslint.alwaysShowStatus": true, "eslint.alwaysShowStatus": true,
"prettier.disableLanguages": ["ts"] "prettier.disableLanguages": [
"ts"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
} }

@ -1,17 +1,17 @@
/* eslint-disable import/order */ /* eslint-disable import/order */
/* eslint-disable import/no-duplicates */ /* eslint-disable import/no-duplicates */
import { LuaError } from './LuaError'
import { Scope } from './Scope' import { Scope } from './Scope'
import { createG } from './lib/globals'
import { operators } from './operators'
import { Table } from './Table' import { Table } from './Table'
import { LuaError } from './LuaError' import { createG } from './lib/globals'
import { libMath } from './lib/math' import { libMath } from './lib/math'
import { libTable } from './lib/table'
import { libString, metatable as stringMetatable } from './lib/string'
import { getLibOS } from './lib/os' import { getLibOS } from './lib/os'
import { getLibPackage } from './lib/package' import { getLibPackage } from './lib/package'
import { LuaType, ensureArray, Config } from './utils' import { libString, metatable as stringMetatable } from './lib/string'
import { libTable } from './lib/table'
import { operators } from './operators'
import { parse as parseScript } from './parser' import { parse as parseScript } from './parser'
import { Config, LuaType, ensureArray } from './utils'
interface Script { interface Script {
exec: () => LuaType exec: () => LuaType
@ -61,13 +61,14 @@ function createEnv(
LUA_PATH: './?.lua', LUA_PATH: './?.lua',
stdin: '', stdin: '',
stdout: console.log, stdout: console.log,
encoding: 'x-user-defined',
...config ...config
} }
const _G = createG(cfg, execChunk) const _G = createG(cfg, execChunk)
const { libPackage, _require } = getLibPackage( const { libPackage, _require } = getLibPackage(
(content, moduleName) => execChunk(_G, parseScript(content), moduleName)[0], (content, moduleName) => execChunk(_G, parseScript(content, cfg.encoding), moduleName)[0],
cfg cfg
) )
const loaded = libPackage.get('loaded') as Table const loaded = libPackage.get('loaded') as Table
@ -111,4 +112,5 @@ function createEnv(
// eslint-disable-next-line import/first // eslint-disable-next-line import/first
import * as utils from './utils' import * as utils from './utils'
export { createEnv, Table, LuaError, utils } export { LuaError, Table, createEnv, utils }

@ -739,12 +739,12 @@ const setExtraInfo = (ast: luaparse.Chunk): void => {
visitProp(ast, scopeID, gotoID) visitProp(ast, scopeID, gotoID)
} }
const parse = (data: string): string => { const parse = (data: string, encodeing: 'pseudo-latin1' | 'x-user-defined' | 'none' = 'none'): string => {
const ast = luaparse.parse(data.replace(/^#.*/, ''), { const ast = luaparse.parse(data.replace(/^#.*/, ''), {
scope: false, scope: false,
comments: false, comments: false,
luaVersion: '5.3', luaVersion: '5.3',
encodingMode: 'x-user-defined' encodingMode: encodeing
}) })
checkGoto(ast) checkGoto(ast)
setExtraInfo(ast) setExtraInfo(ast)
@ -752,3 +752,4 @@ const parse = (data: string): string => {
} }
export { parse } export { parse }

@ -10,6 +10,7 @@ interface Config {
stdin?: string stdin?: string
stdout?: (data: string) => void stdout?: (data: string) => void
osExit?: (code: number) => void osExit?: (code: number) => void
encoding?: 'pseudo-latin1' | 'x-user-defined' | 'none'
} }
/** Pattern to identify a float string value that can validly be converted to a number in Lua */ /** Pattern to identify a float string value that can validly be converted to a number in Lua */
@ -199,18 +200,19 @@ const hasOwnProperty = (obj: Record<string, unknown> | unknown[], key: string |
Object.prototype.hasOwnProperty.call(obj, key) Object.prototype.hasOwnProperty.call(obj, key)
export { export {
LuaType, coerceArgToFunction,
Config,
type,
tostring,
posrelat,
coerceToBoolean,
coerceToNumber,
coerceToString,
coerceArgToNumber, coerceArgToNumber,
coerceArgToString, coerceArgToString,
coerceArgToTable, coerceArgToTable,
coerceArgToFunction, coerceToBoolean,
coerceToNumber,
coerceToString,
Config,
ensureArray, ensureArray,
hasOwnProperty hasOwnProperty,
LuaType,
posrelat,
tostring,
type
} }

Loading…
Cancel
Save