Programming Language support in WML (was '[nowml] tag')
Moderator: Forum Moderators
Forum rules
Before posting a new idea, you must read the following:
Before posting a new idea, you must read the following:
Programming Language support in WML (was '[nowml] tag')
The idea:
In a [nowml] tag, you can let the computer execute C++ commands. (or even other languages, depending if it´s possible)
Pros and cons:
For those who know C++, it can help to do some things WML can´t do. Or things may be done shorter.
Here are two examples of other people´s ideas where it can be used.
http://www.wesnoth.org/forum/viewtopic.php?t=11263
http://www.wesnoth.org/forum/viewtopic.php?t=11063
It may crash very hard, though. But maybe a part could be included that saves the computer from a crash.
What do you think?
EDIT: Have renamed thread something a bit clearer. --Irrevenant
In a [nowml] tag, you can let the computer execute C++ commands. (or even other languages, depending if it´s possible)
Pros and cons:
For those who know C++, it can help to do some things WML can´t do. Or things may be done shorter.
Here are two examples of other people´s ideas where it can be used.
http://www.wesnoth.org/forum/viewtopic.php?t=11263
http://www.wesnoth.org/forum/viewtopic.php?t=11063
It may crash very hard, though. But maybe a part could be included that saves the computer from a crash.
What do you think?
EDIT: Have renamed thread something a bit clearer. --Irrevenant
Last edited by toms on May 20th, 2006, 6:25 am, edited 1 time in total.
First read, then think. Read again, think again. And then post!
- irrevenant
- Moderator Emeritus
- Posts: 3692
- Joined: August 15th, 2005, 7:57 am
- Location: I'm all around you.
Re: What about a [nowml] tag?
Couldn't it be worse than that; couldn't someone use it to infect players computers with malware (viruses, trojans, etc.)?toms wrote:It may crash very hard, though. But maybe a part could be included that saves the computer from a crash.
Want to post a Wesnoth idea? Great! Read these:
Frequently Posted Ideas Thread
Giving your idea the best chance of acceptance
Frequently Posted Ideas Thread
Giving your idea the best chance of acceptance
-
- Posts: 719
- Joined: December 9th, 2003, 9:31 pm
- Contact:
Security issues asside, I believe this is borderline impossible. C++ is a compiled language not an interpreted one which means for code to work it need to be compiled (go figure). So A. we would need to bundle a compiler with wesnoth and B. it would have to be run to whenever this code was encoutered in WML. Absolutely crazy nuts impossible =). Something like Python or Lua would be more feasable, but still not likely as it would also require the interpreter to be bundled, there is a large risk of security issues, and it would still be a relatively massive undertaking for the dev team when WML has been functioning just fine without it.
Signature dropped due to use of img tag
- Maeglin Dubh
- Moderator Emeritus
- Posts: 1154
- Joined: November 16th, 2005, 8:38 pm
- Location: Valley of the Shadow of Death
- Contact:
-
- Retired Developer
- Posts: 2633
- Joined: March 22nd, 2004, 11:22 pm
- Location: An Earl's Roadstead
Well, there are C++ interpreters of sorts out there (look up ROOT at Cern), but if you are going to use an interpreted language, C++ is not really the best choice. With whatever interpreted language you use, you have to make available the data from within the wesnoth code for it to manipulate. The closest to doing something like this is the Python AI, and since python already needs to be included for the AI, despite my dislike of it as a language, it would be the natural thing to use for such a tag. That said, a lot of work needs to go on even with the AI interface for Python, and I don't see putting hooks in everywhere for python to get access to the wesnoth data, since that would be a big pain be a maintenance nightmare and not to mention have potential performance hits. So, basically, I don't see this happening.
"you can already do that with WML"
Fight Creeeping Biggerism!
http://www.wesnoth.org/forum/viewtopic. ... 760#131760
http://www.wesnoth.org/forum/viewtopic. ... 1358#11358
The idea of allowing one to use Python, or some other interpreted language has been around for a while.
This is actually not a bad idea, we'd just need someone to write an interface for Python, much like we have the existing AI interface.
Allowing C++ would not be feasible.
David
This is actually not a bad idea, we'd just need someone to write an interface for Python, much like we have the existing AI interface.
Allowing C++ would not be feasible.
David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
C++:
I wish.
I've considered this myself (for one of my internal projects), but it just won't work unless Wesnoth can compile itself. [The low-level ABI must be compatible, so outsourcing the compiler is not practical.] And that's a harder project than Wesnoth, so I just don't see it happening.
Python:
I suppose that if the WML interpreter was written in Python, then including native Python would be reasonable.
That's a pretty big if. I don't know how much of a speed hit would be involved, and maintaining two versions of the WML interpreter would be impractical without an automatically generated parser from a single machine representation of the (EBNF?) grammar.
Also, note that Python is not stable enough for long-term embedding. There are a number of planned changes (e.g., redefining what 3/2 gives as a result is scheduled for Python 3.0) that would play havoc with embedded Python in WML.
I wish.
I've considered this myself (for one of my internal projects), but it just won't work unless Wesnoth can compile itself. [The low-level ABI must be compatible, so outsourcing the compiler is not practical.] And that's a harder project than Wesnoth, so I just don't see it happening.
Python:
I suppose that if the WML interpreter was written in Python, then including native Python would be reasonable.
That's a pretty big if. I don't know how much of a speed hit would be involved, and maintaining two versions of the WML interpreter would be impractical without an automatically generated parser from a single machine representation of the (EBNF?) grammar.
Also, note that Python is not stable enough for long-term embedding. There are a number of planned changes (e.g., redefining what 3/2 gives as a result is scheduled for Python 3.0) that would play havoc with embedded Python in WML.
-
- Posts: 719
- Joined: December 9th, 2003, 9:31 pm
- Contact:
Another posibility would be lua. Though python can be embedded into other programs, lua was more or less designed to be embedded into other programs. As I understand it you can pick and choose which bits and features of the language to include making it as lightweight or feature rich as Wesnoth would need it to be. It is also more lightweight and easier to embed than python. Its syntax is closer to C (for better or for worse). Angband is a free open source game that has included lua scripting. Lua is also used in commercial games such as FarCry and WoW.
Signature dropped due to use of img tag
I've worked with Lua a bit (abortive Angband variant).
Lua's biggest disadvantage is that it doesn't have good support for reflecting C++ classes/objects...because it doesn't have objects (as of V5). This doesn't matter that much for Angband because it's written in C with a custom FORTRAN-like memory manager, but it gave me problems when trying to convert my variant to non-object-oriented C++.
Something that's truly object-oriented like Wesnoth...I don't see how you'd automate the reflection to LUA, or even do it cleanly by hand. [Boost's python module was designed to reflect C++ classes to Python 2.2, even in MSVC++ 6. It probably would need maintenance for more recent versions of Python.]
[ EDIT: just rechecked docs...Boost.Python is not multithread-aware. Latest version works with Python 2.4 API.]
Lua's biggest disadvantage is that it doesn't have good support for reflecting C++ classes/objects...because it doesn't have objects (as of V5). This doesn't matter that much for Angband because it's written in C with a custom FORTRAN-like memory manager, but it gave me problems when trying to convert my variant to non-object-oriented C++.
Something that's truly object-oriented like Wesnoth...I don't see how you'd automate the reflection to LUA, or even do it cleanly by hand. [Boost's python module was designed to reflect C++ classes to Python 2.2, even in MSVC++ 6. It probably would need maintenance for more recent versions of Python.]
[ EDIT: just rechecked docs...Boost.Python is not multithread-aware. Latest version works with Python 2.4 API.]
- Viliam
- Translator
- Posts: 1341
- Joined: January 30th, 2004, 11:07 am
- Location: Bratislava, Slovakia
- Contact:
I did not work with Lua, only read a few tutorials, but it seems to me that Lua should support object-like syntax.
There is a Lua datatype called "userdata", which contains a C "void *" value -- from Lua's point of view it is a black box; you can assign it to another variable, and compare two Lua variables on equality. When you try to read or write a property on this variable, Lua provides a "fallback" mechanism to extend the syntax, and you can call e.g. a callback function "set_property(object, property, value)" or "get_property(object, property)". It looks complicated, but it means that you can write things like:
Where "unit" is a Lua userdata variable containing a pointer to unit, and "i" is Lua integer variable.
At least this is how the older versions of Lua worked. Now in version 5.1 there is some concept of "metatables", which seems to be a replacement of the "fallback" functions, providing a similar functionality.
There is a Lua datatype called "userdata", which contains a C "void *" value -- from Lua's point of view it is a black box; you can assign it to another variable, and compare two Lua variables on equality. When you try to read or write a property on this variable, Lua provides a "fallback" mechanism to extend the syntax, and you can call e.g. a callback function "set_property(object, property, value)" or "get_property(object, property)". It looks complicated, but it means that you can write things like:
Code: Select all
i = unit.hitpoints
unit.hitpoints = i / 2
At least this is how the older versions of Lua worked. Now in version 5.1 there is some concept of "metatables", which seems to be a replacement of the "fallback" functions, providing a similar functionality.
That confuses structs (data members) with classes (data members and methods). Lua handles C structs fine.
The only way I found to make Lua handle method invocations, was to rewrite the method invocation as a C function. This fails (catastrophically) when virtual member functions need to be rewritten...exactly when you want C++.
The only way I found to make Lua handle method invocations, was to rewrite the method invocation as a C function. This fails (catastrophically) when virtual member functions need to be rewritten...exactly when you want C++.
-
- Posts: 411
- Joined: January 23rd, 2006, 8:28 am