Wombat, bool vs int and C#.

Grimoric

Well-Known Member
Mar 21, 2015
189
48
44
Does anyone know if there is a way to override the compiler and make it work more unsafe like C++, I have never needed to do anything like this before?

The problem is that Wombat is written in a C like scripting style and I try to transfer the code to C# without adding things like Convert functions.

I try to get a better overview of the scripts, that is the reason for all this.

The other option is to load the C++ compiler and do it.

-Grim

** If the code below can be run in C# without changing the code. Problem solved **

C#:
using System;

namespace test
{
    class Program
    {
        public int testTrue()
        {
            return true; // Convert bool to int
        }

        static void Main(string[] args)
        {
            int i = 1;

            if (testTrue()) // Convert int to bool.
            {
                Console.WriteLine("i is {0}.", i);
            }
        }
    }
}


// Out: i is 1.
 

Lokai

Moderator
ServUO Developer
Dec 4, 2014
1,275
215
Western New York State
Shard Name
Test Center
Donate
Donate money to this user
There is an unsafe compiler option for .Net, but it will not allow C# to compile automatic conversion from int to bool. For those users who needed the capability to produce code that would convert int and bool, I believe the recommendation was to create an intermediary function that would handle it manually. For example:
C#:
private int convert_me(bool mybool)
{
    int x = mybool ? 1 : 0;
    return x;
}
 
  • Like
Reactions: Regnak and Grimoric

PyrO

Well-Known Member
Jan 27, 2015
1,185
102
You can also use a nullable int, or just check if the value is > -1 or something. Int to bool doesnt make sense to me, not sure why you need it?

But even unsafe compilation wouldnt allow this, a int struct is not a bool, so it cant convert them directly.
 

Grimoric

Well-Known Member
Mar 21, 2015
189
48
44
Here is a real example. http://wiki.uot2a.com/index.php?title=Script:_Globals

The first function isOnAnyMulti does return an int while requires an object as a parameter.
C-like:
function int isOnAnyMulti(obj Q68S)
{
  return (isAnyMultiBelow(getLocation(Q68S)) != NULL());
}
1. On an OSI server, then check if that is any multi below an object will return the serial of the object under or an empty object with serial 0 while NULL() returns an object with serial 0.
2. These two results are compared as a boolean and is returned to the int function.
3. Sins the server language wombat is C based the integer will be 0 or 1 depending on the boolean returned.

The function is later called in the script like this:

if (isOnAnyMulti(object))
{

}

We have the overloads Convert.ToInt32 and Convert.ToBoolean but using them will be a requirement of replacing 1000 places in the code. Sins this is used again and again to make the code more compact.
 

PyrO

Well-Known Member
Jan 27, 2015
1,185
102
looked through the wiki a little, apparently the wombat language does not have bool at all? Well so it is designed totally different. Redoing the compiler? Uhm not seeing much success there, compilers are very complex.

But you can look into a parser if you really must / want.
 
  • Like
Reactions: Grimoric

Grimoric

Well-Known Member
Mar 21, 2015
189
48
44
Oh, then I guess the only "fix" is to rewrite all the scripts as close as possible in C#. It is just to understand how things were done sins I try to replicate T2A.