From 6a44ff7dc1154b6bc5cf9ef250b536c5fc11519e Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 19 Apr 2009 15:43:56 +0000 Subject: fixed lua module loading Usdx table will be created and has one function (Time()) for now git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1687 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Lua/src/base/UMain.pas | 2 ++ Lua/src/lua/ULuaCore.pas | 31 ++++++++++++-------- Lua/src/lua/ULuaLog.pas | 51 +++++++++++++++++++++------------ Lua/src/lua/ULuaUsdx.pas | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ Lua/src/ultrastardx.dpr | 1 + 5 files changed, 128 insertions(+), 30 deletions(-) create mode 100644 Lua/src/lua/ULuaUsdx.pas (limited to 'Lua') diff --git a/Lua/src/base/UMain.pas b/Lua/src/base/UMain.pas index d0a9afee..e1226c4d 100644 --- a/Lua/src/base/UMain.pas +++ b/Lua/src/base/UMain.pas @@ -421,6 +421,8 @@ begin LuaCore := TLuaCore.Create; + LuaCore.RegisterModule('Log', ULuaLog_Lib_f); + LuaCore.BrowseDir(PluginPath); LuaCore.DumpPlugins; diff --git a/Lua/src/lua/ULuaCore.pas b/Lua/src/lua/ULuaCore.pas index 9f9188c1..9f965567 100644 --- a/Lua/src/lua/ULuaCore.pas +++ b/Lua/src/lua/ULuaCore.pas @@ -177,7 +177,7 @@ var LuaCore: TLuaCore; implementation -uses ULog, UPlatform; +uses ULog, UPlatform, ULuaUsdx; constructor TLuaCore.Create; begin @@ -393,7 +393,7 @@ end; { prepares the given already opened Lua state with the basic usdx environment, e.g.: base and package Modules, - usdx moduleloaders and usdx table } + usdx moduleloader and usdx table } procedure TLuaCore.PrepareState(L: Plua_State); begin //load basic lib functionality @@ -459,27 +459,34 @@ begin {**** Move C-Library and all-in-one module loader backwards, slot 3 is free now } // get package.loaders[4] function - lua_getfield (L, -1, '4'); + lua_pushinteger(L, 5); //push new index + lua_pushinteger(L, 4); //push old index + lua_gettable (L, -3); // and move it to package.loaders[5] - lua_setfield (L, -2, '5'); + lua_settable (L, -3); // get package.loaders[3] function - lua_getfield (L, -1, '3'); + lua_pushinteger(L, 4); //push new index + lua_pushinteger(L, 3); //push old index + lua_gettable (L, -3); // and move it to package.loaders[4] - lua_setfield (L, -2, '4'); + lua_settable (L, -3); {**** now we add the core module to package.loaders[3] } + lua_pushinteger(L, 3); //push new loaders index lua_pushcfunction(L, TLuaCore_ModuleLoader); // and move it to package.loaders[3] - lua_setfield (L, -2, '3'); - + lua_settable (L, -3); //pop both package and package.loaders tables from stack lua_pop(L, 2); + {**** now we create the usdx table } + //at first functions from ULuaUsdx + luaL_register(L, 'Usdx', @ULuaUsdx_Lib_f[0]); end; { returns id of given module, or -1 if module is not found } @@ -522,7 +529,7 @@ begin //we need at least 6 letters //and first 5 letters have to be usdx. - if (Length(Name) > 5) and (copy(Name, 1, 5)='usdx.') then + if (Length(Name) > 5) and (copy(Name, 1, 5)='Usdx.') then begin ID := LuaCore.GetModuleIdByName(copy(Name, 6, Length(Name) - 5)); If (ID >= 0) then @@ -535,7 +542,7 @@ begin lua_pushString(L, PChar('usdx module "' + Name + '" couldn''t be found')); end else - lua_pushString(L, PChar('module doesn''t have "usdx." prefix')); + lua_pushString(L, PChar('module doesn''t have "Usdx." prefix')); end else @@ -556,7 +563,7 @@ begin begin Id := lua_ToInteger(L, lua_upvalueindex(1)); - luaL_register(L, PChar('usdx.' + LuaCore.Modules[Id].Name), @LuaCore.Modules[Id].Functions[0]); + luaL_register(L, PChar('Usdx.' + LuaCore.Modules[Id].Name), @LuaCore.Modules[Id].Functions[0]); Result := 1; //return table end @@ -696,7 +703,7 @@ end; { returns true if plugin has called register } function TLuaPlugin.HasRegistred: Boolean; begin - Result := (Self.sName = 'not registred'); + Result := (Self.sName <> 'not registred'); end; procedure TLuaPlugin.PausePlugin(doPause: Boolean); diff --git a/Lua/src/lua/ULuaLog.pas b/Lua/src/lua/ULuaLog.pas index 51b9797d..95efaa19 100644 --- a/Lua/src/lua/ULuaLog.pas +++ b/Lua/src/lua/ULuaLog.pas @@ -40,6 +40,39 @@ uses function luaopen_Log (L: Plua_State): Integer; cdecl; +function ULuaLog_LogError(L: Plua_State): Integer; cdecl; +function ULuaLog_LogMsg(L: Plua_State): Integer; cdecl; +function ULuaLog_BenchmarkStart(L: Plua_State): Integer; cdecl; +function ULuaLog_BenchmarkEnd(L: Plua_State): Integer; cdecl; +function ULuaLog_LogBenchmark(L: Plua_State): Integer; cdecl; +function ULuaLog_LogDebug(L: Plua_State): Integer; cdecl; +function ULuaLog_LogInfo(L: Plua_State): Integer; cdecl; +function ULuaLog_LogStatus(L: Plua_State): Integer; cdecl; +function ULuaLog_LogWarn(L: Plua_State): Integer; cdecl; +function ULuaLog_LogCritical(L: Plua_State): Integer; cdecl; +function ULuaLog_CriticalError(L: Plua_State): Integer; cdecl; +function ULuaLog_GetLogLevel(L: Plua_State): Integer; cdecl; +function ULuaLog_SetLogLevel(L: Plua_State): Integer; cdecl; + + +const + ULuaLog_Lib_f: array [0..13] of lual_reg = ( + (name:'LogError';func:ULuaLog_LogError), + (name:'LogMsg';func:ULuaLog_LogMsg), + (name:'BenchmarkStart';func:ULuaLog_BenchmarkStart), + (name:'BenchmarkEnd';func:ULuaLog_BenchmarkEnd), + (name:'LogBenchmark';func:ULuaLog_LogBenchmark), + (name:'LogDebug';func:ULuaLog_LogDebug), + (name:'LogInfo';func:ULuaLog_LogInfo), + (name:'LogStatus';func:ULuaLog_LogStatus), + (name:'LogWarn';func:ULuaLog_LogWarn), + (name:'LogCritical';func:ULuaLog_LogCritical), + (name:'CriticalError';func:ULuaLog_CriticalError), + (name:'SetLogLevel';func:ULuaLog_GetLogLevel), + (name:'GetLogLevel';func:ULuaLog_SetLogLevel), + (name:nil;func:nil) + ); + implementation function ULuaLog_LogError(L: Plua_State): Integer; cdecl; @@ -126,24 +159,6 @@ begin result:=0; // number of results end; -const - ULuaLog_Lib_f: array [0..13] of lual_reg = ( - (name:'LogError';func:ULuaLog_LogError), - (name:'LogMsg';func:ULuaLog_LogMsg), - (name:'BenchmarkStart';func:ULuaLog_BenchmarkStart), - (name:'BenchmarkEnd';func:ULuaLog_BenchmarkEnd), - (name:'LogBenchmark';func:ULuaLog_LogBenchmark), - (name:'LogDebug';func:ULuaLog_LogDebug), - (name:'LogInfo';func:ULuaLog_LogInfo), - (name:'LogStatus';func:ULuaLog_LogStatus), - (name:'LogWarn';func:ULuaLog_LogWarn), - (name:'LogCritical';func:ULuaLog_LogCritical), - (name:'CriticalError';func:ULuaLog_CriticalError), - (name:'SetLogLevel';func:ULuaLog_GetLogLevel), - (name:'GetLogLevel';func:ULuaLog_SetLogLevel), - (name:nil;func:nil) - ); - function luaopen_Log (L: Plua_State): Integer; cdecl; begin luaL_register(L,'Log',@ULuaLog_Lib_f[0]); diff --git a/Lua/src/lua/ULuaUsdx.pas b/Lua/src/lua/ULuaUsdx.pas new file mode 100644 index 00000000..558a47cd --- /dev/null +++ b/Lua/src/lua/ULuaUsdx.pas @@ -0,0 +1,73 @@ +{* UltraStar Deluxe - Karaoke Game + * + * UltraStar Deluxe is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $URL: https://ultrastardx.svn.sourceforge.net/svnroot/ultrastardx/branches/experimental/Lua/src/lua/ULuaGl.pas $ + * $Id: ULuaGl.pas 1555 2009-01-11 18:19:42Z Hawkear $ + *} + +unit ULuaUsdx; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses ULua; + +{ some basic lua c functions from usdx table } + +{ usdx.time - returns sdl_time to have time numbers comparable with + ultrastar delux ones. No Arguments } +function ULuaUsdx_Time(L: Plua_State): Integer; cdecl; +function ULuaUsdx_(L: Plua_State): Integer; cdecl; + +const + ULuaUsdx_Lib_f: array [0..1] of lual_reg = ( + (name:'Time'; func:ULuaUsdx_Time), + (name:nil; func:nil) + ); + +implementation +uses SDL; + +function ULuaUsdx_Time(L: Plua_State): Integer; cdecl; + var top: Integer; +begin + //remove arguments (if any) + top := lua_gettop(L); + + If (top > 0) then + lua_pop(L, top); + + //push result + lua_pushinteger(L, SDL_GetTicks); + Result := 1; //one result +end; + +function ULuaUsdx_(L: Plua_State): Integer; cdecl; +begin + +end; + +end. \ No newline at end of file diff --git a/Lua/src/ultrastardx.dpr b/Lua/src/ultrastardx.dpr index 296a330d..10d1e823 100644 --- a/Lua/src/ultrastardx.dpr +++ b/Lua/src/ultrastardx.dpr @@ -151,6 +151,7 @@ uses ULuaTexture in 'lua\ULuaTexture.pas', UHookableEvent in 'lua\UHookableEvent.pas', ULuaCore in 'lua\ULuaCore.pas', + ULuaUsdx in 'lua\ULuaUsdx.pas', //------------------------------ //Includes - Menu System -- cgit v1.2.3