|
|
|
@ -10,7 +10,7 @@ import { libTable } from './lib/table'
|
|
|
|
import { libString, metatable as stringMetatable } from './lib/string'
|
|
|
|
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, hasOwnProperty } from './utils'
|
|
|
|
import { LuaType, ensureArray, Config } from './utils'
|
|
|
|
import { parse as parseScript } from './parser'
|
|
|
|
import { parse as parseScript } from './parser'
|
|
|
|
|
|
|
|
|
|
|
|
interface Script {
|
|
|
|
interface Script {
|
|
|
|
@ -56,7 +56,6 @@ function createEnv(
|
|
|
|
parse: (script: string) => Script
|
|
|
|
parse: (script: string) => Script
|
|
|
|
parseFile: (path: string) => Script
|
|
|
|
parseFile: (path: string) => Script
|
|
|
|
loadLib: (name: string, value: Table) => void
|
|
|
|
loadLib: (name: string, value: Table) => void
|
|
|
|
extendLib: (name: string, value: Table) => void
|
|
|
|
|
|
|
|
} {
|
|
|
|
} {
|
|
|
|
const cfg: Config = {
|
|
|
|
const cfg: Config = {
|
|
|
|
LUA_PATH: './?.lua',
|
|
|
|
LUA_PATH: './?.lua',
|
|
|
|
@ -78,24 +77,6 @@ function createEnv(
|
|
|
|
loaded.rawset(name, value)
|
|
|
|
loaded.rawset(name, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const extendLib = (name: string, value: Table): void => {
|
|
|
|
|
|
|
|
const lib = _G.rawget(name)
|
|
|
|
|
|
|
|
if (lib instanceof Table) {
|
|
|
|
|
|
|
|
for (let i = 1; i < value.numValues.length; i++) {
|
|
|
|
|
|
|
|
if (hasOwnProperty(value.numValues, i)) lib.rawset(i, value.numValues[i])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const key in value.strValues) {
|
|
|
|
|
|
|
|
if (hasOwnProperty(value.strValues, key)) lib.rawset(key, value.strValues[key])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < value.keys.length; i++) {
|
|
|
|
|
|
|
|
lib.rawset(value.keys[i], value.values[i])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadLib(name, value)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadLib('_G', _G)
|
|
|
|
loadLib('_G', _G)
|
|
|
|
loadLib('package', libPackage)
|
|
|
|
loadLib('package', libPackage)
|
|
|
|
loadLib('math', libMath)
|
|
|
|
loadLib('math', libMath)
|
|
|
|
@ -124,8 +105,7 @@ function createEnv(
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
parse,
|
|
|
|
parse,
|
|
|
|
parseFile,
|
|
|
|
parseFile,
|
|
|
|
loadLib,
|
|
|
|
loadLib
|
|
|
|
extendLib
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|