sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
authornemo
Fri, 12 Aug 2011 10:36:37 -0400
changeset 5549 ccfb9b8ab9d1
parent 5547 2fe1d68a102c
child 5551 0897b947e7a0
sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
QTfrontend/pageeditteam.cpp
hedgewars/LuaPas.pas
hedgewars/uScript.pas
--- a/QTfrontend/pageeditteam.cpp	Thu Aug 11 23:07:45 2011 -0400
+++ b/QTfrontend/pageeditteam.cpp	Fri Aug 12 10:36:37 2011 -0400
@@ -358,14 +358,16 @@
     mySdli->SDLMusicInit();
     
     tmpdir.cd(cfgdir->absolutePath());
-    if (!tmpdir.cd("Data/Sounds/voices") && !tmpdir.cd(CBVoicepack->currentText())) {
+    tmpdir.cd("Data/Sounds/voices");
+    tmpdir.cd(CBVoicepack->currentText());
+    
+    if (!tmpdir.exists()) {
         tmpdir.cd(datadir->absolutePath());
         tmpdir.cd("Sounds/voices");
         tmpdir.cd(CBVoicepack->currentText());
     }
 
     QStringList list = tmpdir.entryList(QStringList() << "Illgetyou.ogg" << "Incoming.ogg" << "Stupid.ogg" << "Coward.ogg" << "Firstblood.ogg", QDir::Files);
-
     if (list.size()) {
         sound = Mix_LoadWAV(QString(tmpdir.absolutePath() + "/" + list[rand() % list.size()]).toLocal8Bit().constData());
         Mix_PlayChannel(-1, sound, 0);
--- a/hedgewars/LuaPas.pas	Thu Aug 11 23:07:45 2011 -0400
+++ b/hedgewars/LuaPas.pas	Fri Aug 12 10:36:37 2011 -0400
@@ -416,7 +416,7 @@
 procedure lua_setglobal(L : Plua_State; s : PChar);
 procedure lua_getglobal(L : Plua_State; s : PChar);
 
-function lua_tostring(L : Plua_State; idx : LongInt) : PChar;
+function lua_tostring(L : Plua_State; idx : LongInt) : shortstring;
 
 
 (*
@@ -757,7 +757,7 @@
 implementation
 
 uses
-  SysUtils;
+  SysUtils, Strings;
 
 (*****************************************************************************)
 (*                            luaconfig.h                                    *)
@@ -872,9 +872,9 @@
   lua_getfield(L, LUA_GLOBALSINDEX, s);
 end;
 
-function lua_tostring(L : Plua_State; idx : LongInt) : PChar;
+function lua_tostring(L : Plua_State; idx : LongInt) : shortstring;
 begin
-  lua_tostring := lua_tolstring(L, idx, nil);
+  lua_tostring := Strings.StrPas(lua_tolstring(L, idx, nil));
 end;
 
 function lua_open : Plua_State;
--- a/hedgewars/uScript.pas	Thu Aug 11 23:07:45 2011 -0400
+++ b/hedgewars/uScript.pas	Fri Aug 12 10:36:37 2011 -0400
@@ -153,7 +153,7 @@
 begin
     if lua_gettop(L) = 1 then
         begin
-        WriteLnToConsole('Lua: ' + StrPas(lua_tostring(L ,1)));
+        WriteLnToConsole('Lua: ' + lua_tostring(L ,1));
         end
     else
         LuaError('Lua: Wrong number of parameters passed to WriteLnToConsole!');
@@ -164,7 +164,7 @@
 begin
     if lua_gettop(L) = 1 then
         begin
-        ParseCommand(StrPas(lua_tostring(L ,1)), true);
+        ParseCommand(lua_tostring(L ,1), true);
         end
     else
         LuaError('Lua: Wrong number of parameters passed to ParseCommand!');
@@ -175,7 +175,7 @@
 begin
     if lua_gettop(L) = 5 then
         begin
-        ShowMission(StrPas(lua_tostring(L, 1)), StrPas(lua_tostring(L, 2)), StrPas(lua_tostring(L, 3)), lua_tointeger(L, 4), lua_tointeger(L, 5));
+        ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
         end
     else
         LuaError('Lua: Wrong number of parameters passed to ShowMission!');
@@ -192,10 +192,10 @@
 function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
 begin
     if lua_gettop(L) = 1 then
-        AddCaption(StrPas(lua_tostring(L, 1)), cWhiteColor, capgrpMessage)
+        AddCaption(lua_tostring(L, 1), cWhiteColor, capgrpMessage)
     else if lua_gettop(L) = 3 then
         begin
-        AddCaption(StrPas(lua_tostring(L, 1)), lua_tointeger(L, 2) shr 8, TCapGroup(lua_tointeger(L, 3)));
+        AddCaption(lua_tostring(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(lua_tointeger(L, 3)));
         end
     else
         LuaError('Lua: Wrong number of parameters passed to AddCaption!');
@@ -720,7 +720,7 @@
         gear:= GearByUID(lua_tointeger(L, 1));
         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
 
-	    hogName:= StrPas(lua_tostring(L, 2));
+	    hogName:= lua_tostring(L, 2);
             gear^.Hedgehog^.Name:= hogName;
 
 	    FreeTexture(gear^.Hedgehog^.NameTagTex);
@@ -857,7 +857,7 @@
             vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true);
             if vgear <> nil then
                begin
-               vgear^.Text:= StrPas(lua_tostring(L, 2));
+               vgear^.Text:= lua_tostring(L, 2);
                vgear^.Hedgehog:= gear^.Hedgehog;
                vgear^.FrameTicks:= lua_tointeger(L, 3);
                if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then vgear^.FrameTicks:= 1;
@@ -1130,12 +1130,12 @@
  Something is very wrong here.
  For some reason, if I assign voice after fort (or don't use the variable) it is empty.
 *)
-        voice:= StrPas(lua_tostring(L, 5));
-        ParseCommand('addteam x ' + StrPas(lua_tostring(L, 2)) + ' ' + StrPas(lua_tostring(L, 1)), true);
-        ParseCommand('grave ' + StrPas(lua_tostring(L, 3)), true);
-        ParseCommand('fort ' + StrPas(lua_tostring(L, 4)), true);
+        ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true);
+        voice:= lua_tostring(L, 5);
+        ParseCommand('grave ' + lua_tostring(L, 3), true);
+        ParseCommand('fort ' + lua_tostring(L, 4), true);
         ParseCommand('voicepack ' + voice, true);
-        if (np = 6) then ParseCommand('flag ' + StrPas(lua_tostring(L, 6)), true);
+        if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true);
         CurrentTeam^.Binds:= DefaultBinds
         // fails on x64
         //lua_pushinteger(L, LongInt(CurrentTeam));
@@ -1153,8 +1153,8 @@
         end
     else
         begin
-        temp:= StrPas(lua_tostring(L, 4));
-        ParseCommand('addhh ' + StrPas(lua_tostring(L, 2)) + ' ' + StrPas(lua_tostring(L, 3)) + ' ' + StrPas(lua_tostring(L, 1)), true);
+        temp:= lua_tostring(L, 4);
+        ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true);
         ParseCommand('hat ' + temp, true);
         lua_pushinteger(L, CurrentHedgehog^.Gear^.uid);
         end;
@@ -1458,7 +1458,7 @@
         begin
         gear:= GearByUID(lua_tointeger(L, 1));
         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
-            hat:= StrPas(lua_tostring(L, 2));
+            hat:= lua_tostring(L, 2);
             gear^.Hedgehog^.Hat:= hat;
             LoadHedgehogHat(gear, hat);
         end;
@@ -1494,7 +1494,7 @@
     WriteLnToConsole('Lua: Stack (' + inttostr(n) + ' elements):');
     for i:= 1 to n do
         if not lua_isboolean(luaState, i) then
-            WriteLnToConsole('Lua:  ' + inttostr(i) + ': ' + StrPas(lua_tostring(luaState, i)))
+            WriteLnToConsole('Lua:  ' + inttostr(i) + ': ' + lua_tostring(luaState, i))
         else if lua_toboolean(luaState, i) then
             WriteLnToConsole('Lua:  ' + inttostr(i) + ': true')
         else
@@ -1534,7 +1534,7 @@
 function ScriptGetString(name : shortstring) : shortstring;
 begin
 lua_getglobal(luaState, Str2PChar(name));
-ScriptGetString:= StrPas(lua_tostring(luaState, -1));
+ScriptGetString:= lua_tostring(luaState, -1);
 lua_pop(luaState, 1);
 end;
 
@@ -1611,7 +1611,7 @@
 if ret <> 0 then
     begin
     LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
-    LuaError('Lua: ' + StrPas(lua_tostring(luaState, -1)));
+    LuaError('Lua: ' + lua_tostring(luaState, -1));
     end
 else
     begin
@@ -1647,7 +1647,7 @@
 lua_getglobal(luaState, Str2PChar(fname));
 if lua_pcall(luaState, 0, 0, 0) <> 0 then
     begin
-    LuaError('Lua: Error while calling ' + fname + ': ' + StrPas(lua_tostring(luaState, -1)));
+    LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
     lua_pop(luaState, 1)
     end;
 GetGlobals;
@@ -1662,12 +1662,12 @@
 lua_pushstring(luaState, Str2PChar(value));
 if lua_pcall(luaState, 2, 1, 0) <> 0 then
     begin
-    LuaError('Lua: Error while calling ParseCommandOverride: ' + StrPas(lua_tostring(luaState, -1)));
+    LuaError('Lua: Error while calling ParseCommandOverride: ' + lua_tostring(luaState, -1));
     lua_pop(luaState, 1)
     end
 else
     begin
-    ParseCommandOverride:= StrPas(lua_tostring(luaState, -1));
+    ParseCommandOverride:= lua_tostring(luaState, -1);
     lua_pop(luaState, 1)
     end;
 end;
@@ -1700,7 +1700,7 @@
 ScriptCall:= 0;
 if lua_pcall(luaState, 4, 1, 0) <> 0 then
     begin
-    LuaError('Lua: Error while calling ' + fname + ': ' + StrPas(lua_tostring(luaState, -1)));
+    LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
     lua_pop(luaState, 1)
     end
 else