|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
/* eslint-disable import/order */
|
|
|
|
|
|
|
|
/* eslint-disable import/no-duplicates */
|
|
|
|
import { Scope } from './Scope'
|
|
|
|
import { Scope } from './Scope'
|
|
|
|
import { createG } from './lib/globals'
|
|
|
|
import { createG } from './lib/globals'
|
|
|
|
import { operators } from './operators'
|
|
|
|
import { operators } from './operators'
|
|
|
|
@ -49,6 +51,7 @@ function createEnv(
|
|
|
|
): {
|
|
|
|
): {
|
|
|
|
run: (script: string) => LuaType
|
|
|
|
run: (script: string) => LuaType
|
|
|
|
runfile: (path: string) => LuaType
|
|
|
|
runfile: (path: string) => LuaType
|
|
|
|
|
|
|
|
loadLib: (name: string, value: Table) => void
|
|
|
|
} {
|
|
|
|
} {
|
|
|
|
const cfg: Config = {
|
|
|
|
const cfg: Config = {
|
|
|
|
LUA_PATH: './?.lua',
|
|
|
|
LUA_PATH: './?.lua',
|
|
|
|
@ -65,17 +68,17 @@ function createEnv(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
const loaded = libPackage.get('loaded') as Table
|
|
|
|
const loaded = libPackage.get('loaded') as Table
|
|
|
|
|
|
|
|
|
|
|
|
const load = (name: string, value: Table): void => {
|
|
|
|
const loadLib = (name: string, value: Table): void => {
|
|
|
|
_G.rawset(name, value)
|
|
|
|
_G.rawset(name, value)
|
|
|
|
loaded.rawset(name, value)
|
|
|
|
loaded.rawset(name, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
load('_G', _G)
|
|
|
|
loadLib('_G', _G)
|
|
|
|
load('package', libPackage)
|
|
|
|
loadLib('package', libPackage)
|
|
|
|
load('math', libMath)
|
|
|
|
loadLib('math', libMath)
|
|
|
|
load('table', libTable)
|
|
|
|
loadLib('table', libTable)
|
|
|
|
load('string', libString)
|
|
|
|
loadLib('string', libString)
|
|
|
|
load('os', getLibOS(cfg))
|
|
|
|
loadLib('os', getLibOS(cfg))
|
|
|
|
|
|
|
|
|
|
|
|
_G.rawset('require', _require)
|
|
|
|
_G.rawset('require', _require)
|
|
|
|
|
|
|
|
|
|
|
|
@ -91,8 +94,11 @@ function createEnv(
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
run,
|
|
|
|
run,
|
|
|
|
runfile
|
|
|
|
runfile,
|
|
|
|
|
|
|
|
loadLib
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export { createEnv }
|
|
|
|
// eslint-disable-next-line import/first
|
|
|
|
|
|
|
|
import * as utils from './utils'
|
|
|
|
|
|
|
|
export { createEnv, Table, LuaError, utils }
|
|
|
|
|