11import { satisfies } from "semver" ;
22import { 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" ;
44
55type luaBindingFactoryFunc = ( luaGlue : LuaEmscriptenModule ) => Partial < Lua > ;
66const luaBindings : Record < string , luaBindingFactoryFunc > = {
@@ -23,6 +23,10 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
2323 } ,
2424 "5.0.x" : function ( luaGlue : LuaEmscriptenModule ) {
2525 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+ } ,
2630 lua_getfield : function ( L : LuaState , index : number , k : string ) {
2731 ( this as Lua ) . lua_pushstring ( L , k ) ;
2832 return ( this as Lua ) . lua_gettable ( L , index ) ;
@@ -51,12 +55,16 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
5155 lua_tostring : luaGlue . cwrap ( "lua_tostring" , "number" , [ "number" , "number" ] )
5256 } ;
5357 } ,
54- "<= 5.1.0 " : function ( luaGlue : LuaEmscriptenModule ) {
58+ "5.1.x " : function ( _ : LuaEmscriptenModule ) {
5559 return {
5660 // #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, s)
5761 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 {
6068 // Need to overwrite because in lua 5.1 this is a function and not a #define (5.2 and higher)
6169 lua_pcall : luaGlue . cwrap ( "lua_pcall" , "number" , [ "number" , "number" , "number" , "number" ] ) ,
6270 // TODO there might be some way to mimic pcallk behaviour with 5.1 somehow
@@ -93,7 +101,7 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
93101 ] )
94102 } ;
95103 } ,
96- "<=5.2.0 " : function ( luaGlue : LuaEmscriptenModule ) {
104+ "<=5.2.x " : function ( luaGlue : LuaEmscriptenModule ) {
97105 return {
98106 lua_copy : function ( _L : LuaState , _fromIndex : number , _toIndex : number ) {
99107 throw "lua_copy not supported with Lua 5.2 and lower" ;
@@ -158,7 +166,7 @@ const lauxBindings: Record<string, lauxBindingFactoryFunc> = {
158166 luaL_newstate : luaGlue . cwrap ( "lua_open" , "number" , [ ] ) ,
159167 }
160168 } ,
161- "<=5.1.0 " : function ( luaGlue : LuaEmscriptenModule , _lua : Lua ) {
169+ "<=5.1.x " : function ( luaGlue : LuaEmscriptenModule , _lua : Lua ) {
162170 return {
163171 luaL_loadbuffer : luaGlue . cwrap ( "luaL_loadbuffer" , "number" , [ "number" , "string" , "number" , "string" ] ) ,
164172 }
0 commit comments