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.autoFixOnSave": 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/no-duplicates */
import { LuaError } from './LuaError'
import { Scope } from './Scope'
import { createG } from './lib/globals'
import { operators } from './operators'
import { Table } from './Table'
import { LuaError } from './LuaError'
import { createG } from './lib/globals'
import { libMath } from './lib/math'
import { libTable } from './lib/table'
import { libString, metatable as stringMetatable } from './lib/string'
import { getLibOS } from './lib/os'
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 { Config, LuaType, ensureArray } from './utils'
interface Script {
exec: () => LuaType
@ -61,13 +61,14 @@ function createEnv(
LUA_PATH: './?.lua',
stdin: '',
stdout: console.log,
encoding: 'x-user-defined',
...config
}
const _G = createG(cfg, execChunk)
const { libPackage, _require } = getLibPackage(
(content, moduleName) => execChunk(_G, parseScript(content), moduleName)[0],
(content, moduleName) => execChunk(_G, parseScript(content, cfg.encoding), moduleName)[0],
cfg
)
const loaded = libPackage.get('loaded') as Table
@ -111,4 +112,5 @@ function createEnv(
// eslint-disable-next-line import/first
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)
}
const parse = (data: string): string => {
const parse = (data: string, encodeing: 'pseudo-latin1' | 'x-user-defined' | 'none' = 'none'): string => {
const ast = luaparse.parse(data.replace(/^#.*/, ''), {
scope: false,
comments: false,
luaVersion: '5.3',
encodingMode: 'x-user-defined'
encodingMode: encodeing
})
checkGoto(ast)
setExtraInfo(ast)
@ -752,3 +752,4 @@ const parse = (data: string): string => {
}
export { parse }

@ -10,6 +10,7 @@ interface Config {
stdin?: string
stdout?: (data: string) => 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 */
@ -199,18 +200,19 @@ const hasOwnProperty = (obj: Record<string, unknown> | unknown[], key: string |
Object.prototype.hasOwnProperty.call(obj, key)
export {
LuaType,
Config,
type,
tostring,
posrelat,
coerceToBoolean,
coerceToNumber,
coerceToString,
coerceArgToFunction,
coerceArgToNumber,
coerceArgToString,
coerceArgToTable,
coerceArgToFunction,
coerceToBoolean,
coerceToNumber,
coerceToString,
Config,
ensureArray,
hasOwnProperty
hasOwnProperty,
LuaType,
posrelat,
tostring,
type
}

Loading…
Cancel
Save