1
1
import { satisfies } from "semver" ;
2
2
import { LuaEmscriptenModule } from "./glue/glue" ;
3
- import { LauxLib , Lua , LuaLib , LuaState , LUA_GLOBALSINDEX , LUA_MULTRET } from "./lua" ;
3
+ import { LauxLib , Lua , LuaLib , LuaState , LUA_GLOBALSINDEX_50 , LUA_GLOBALSINDEX_51 , LUA_MULTRET } from "./lua" ;
4
4
5
5
type luaBindingFactoryFunc = ( luaGlue : LuaEmscriptenModule ) => Partial < Lua > ;
6
6
const luaBindings : Record < string , luaBindingFactoryFunc > = {
@@ -23,6 +23,10 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
23
23
} ,
24
24
"5.0.x" : function ( luaGlue : LuaEmscriptenModule ) {
25
25
return {
26
+ // #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, s)
27
+ lua_getglobal : function ( L : LuaState , name : string ) {
28
+ return ( this as Lua ) . lua_getfield ( L , LUA_GLOBALSINDEX_50 , name ) ;
29
+ } ,
26
30
lua_getfield : function ( L : LuaState , index : number , k : string ) {
27
31
( this as Lua ) . lua_pushstring ( L , k ) ;
28
32
return ( this as Lua ) . lua_gettable ( L , index ) ;
@@ -51,12 +55,16 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
51
55
lua_tostring : luaGlue . cwrap ( "lua_tostring" , "number" , [ "number" , "number" ] )
52
56
} ;
53
57
} ,
54
- "<= 5.1.0 " : function ( luaGlue : LuaEmscriptenModule ) {
58
+ "5.1.x " : function ( _ : LuaEmscriptenModule ) {
55
59
return {
56
60
// #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, s)
57
61
lua_getglobal : function ( L : LuaState , name : string ) {
58
- return ( this as Lua ) . lua_getfield ( L , LUA_GLOBALSINDEX , name ) ;
59
- } ,
62
+ return ( this as Lua ) . lua_getfield ( L , LUA_GLOBALSINDEX_51 , name ) ;
63
+ }
64
+ } ;
65
+ } ,
66
+ "<=5.1.x" : function ( luaGlue : LuaEmscriptenModule ) {
67
+ return {
60
68
// Need to overwrite because in lua 5.1 this is a function and not a #define (5.2 and higher)
61
69
lua_pcall : luaGlue . cwrap ( "lua_pcall" , "number" , [ "number" , "number" , "number" , "number" ] ) ,
62
70
// TODO there might be some way to mimic pcallk behaviour with 5.1 somehow
@@ -93,7 +101,7 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
93
101
] )
94
102
} ;
95
103
} ,
96
- "<=5.2.0 " : function ( luaGlue : LuaEmscriptenModule ) {
104
+ "<=5.2.x " : function ( luaGlue : LuaEmscriptenModule ) {
97
105
return {
98
106
lua_copy : function ( _L : LuaState , _fromIndex : number , _toIndex : number ) {
99
107
throw "lua_copy not supported with Lua 5.2 and lower" ;
@@ -158,7 +166,7 @@ const lauxBindings: Record<string, lauxBindingFactoryFunc> = {
158
166
luaL_newstate : luaGlue . cwrap ( "lua_open" , "number" , [ ] ) ,
159
167
}
160
168
} ,
161
- "<=5.1.0 " : function ( luaGlue : LuaEmscriptenModule , _lua : Lua ) {
169
+ "<=5.1.x " : function ( luaGlue : LuaEmscriptenModule , _lua : Lua ) {
162
170
return {
163
171
luaL_loadbuffer : luaGlue . cwrap ( "luaL_loadbuffer" , "number" , [ "number" , "string" , "number" , "string" ] ) ,
164
172
}
0 commit comments