Importing a library problem

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
carlcyber
Posts: 163
Joined: Thu Jan 27, 2005 1:04 am

Importing a library problem

Post by carlcyber »

I'm writing a library which includes other files. When I compile a normal script that imports my library, acc(1331) refuses to compile. Is this an acc bug or my fault?
For example,

Code: Select all

acc.exe -h Main.acs
This cannot be compiled
  • Main.acs

    Code: Select all

    #import "Library.acs"
    
    Script 1(void)
    {
    	TestFunction();
    }
    Library.acs

    Code: Select all

    #library "Library"
    
    #include "Inc.acs" // Here is my problem
    Inc.acs

    Code: Select all

    Function void TestFunction(void)
    {
    }
This can be compiled
  • Main.acs

    Code: Select all

    #import "Library.acs"
    
    Script 1(void)
    {
    	TestFunction();
    }
    Library.acs

    Code: Select all

    #library "Library"
    
    Function void TestFunction(void)
    {
    }
    Inc.acs

    Code: Select all

    // Not necessary
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Re: Importing a library problem

Post by skadoomer »

-h is for hexen compatibility only, where libraries aren't supported me thinks.
User avatar
Zhs2
Posts: 1300
Joined: Fri Nov 07, 2008 3:29 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Maryland, USA, but probably also in someone's mod somewhere
Contact:

Re: Importing a library problem

Post by Zhs2 »

carlcyber wrote:I'm writing a library which includes other files. When I compile a normal script that imports my library, acc(1331) refuses to compile. Is this an acc bug or my fault?
It may be an ACC bug, depending on which version you have. Have you tried grabbing the new one? An ACS importing bug was fixed in that version, if I'm not mistaken. Oh, and yeh, if you're compiling for regular ol' Hexen, you might be outta luck, but I'm not sure...
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: Importing a library problem

Post by Macil »

You don't need the -h as others said, and you're also missing the line

Code: Select all

#include "zcommon.acs"
in your files.
carlcyber
Posts: 163
Joined: Thu Jan 27, 2005 1:04 am

Re: Importing a library problem

Post by carlcyber »

hmm, I'm using such command line parameter for years and totally forget what -h represents, now they come back again =:)
However, including "zcommon.acs" and using the newest acc doesn't help.
acc1331 wrote:Line 5 in file "Main.acs" ...
Main.acs:5: Function testfunction is used but not defined.
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Re: Importing a library problem

Post by skadoomer »

I have no idea if that is even supposed to work the way you've structured it. The rule of thumb is you must import the file into your script that includes the function you need to use. If you turn inc.acs into a library, the whole thing should work fine.
carlcyber
Posts: 163
Joined: Thu Jan 27, 2005 1:04 am

Re: Importing a library problem

Post by carlcyber »

I've read the source of acc 1.47. In Parse.c,

Code: Select all

static void OuterInclude(void)
{
	// Don't include inside an import
	...
}
I guess this might be something related to the article "New ACC!" in the news page of zdoom.
Apparently they intended to block such action, but, as the library gows, people might want to spilt them into small files grouped by the same function.
Without this, someone might suffer a big pain maintaining the whole library in a single file.

Maybe we can spilt a big library into other small libraries, I haven't thought about this seriously.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: Importing a library problem

Post by Macil »

I guess this was to prevent ACC from reading the zcommon.acs included by a library, and so on.
carlcyber
Posts: 163
Joined: Thu Jan 27, 2005 1:04 am

Re: Importing a library problem

Post by carlcyber »

Agent ME wrote:I guess this was to prevent ACC from reading the zcommon.acs included by a library, and so on.
OK, that makes sense.

Now I merge all the files into a 25K file, no more includes other than zcommon.acs. It still doesn't work. Currently I don't have time to look deeper into the problem, but I feel that the acc doesn't work as it should. If anyone has your own library, please recompile it by the newest acc and share your experience with me, thanks. =:)
(Not just to recompile the library itself, use "#import" please.)
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Importing a library problem

Post by randi »

carlcyber wrote:I guess this might be something related to the article "New ACC!" in the news page of zdoom.
No, it's been like that ever since libraries were added.
carlcyber wrote:Maybe we can spilt a big library into other small libraries, I haven't thought about this seriously.
Yes, you can do that.
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Re: Importing a library problem

Post by skadoomer »

carlcyber wrote:Maybe we can spilt a big library into other small libraries, I haven't thought about this seriously.
The project I'm working with has 23 libraries, each controlling something different. Really, its all about how you want to organize something. I have a library for common functions (stuff used in all libraries), a library for hudmessages math, and one purely for defined terms. I'd be glad to help you if you have any further questions about this stuff.
carlcyber
Posts: 163
Joined: Thu Jan 27, 2005 1:04 am

Re: Importing a library problem

Post by carlcyber »

Thank you for all your replies, I will give some time getting used to this.
And thank you for your kindness skadoomer. I'll ask you if I really don't have an idea.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: Importing a library problem

Post by Macil »

Can libraries #import each other? How does that work out?

If in a map script I #import library A, which #imports library B and uses some functions / variables in that, will that work correctly? Can the map script also use variables and functions in library B?
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Re: Importing a library problem

Post by skadoomer »

Agent ME wrote:Can libraries #import each other? How does that work out?

If in a map script I #import library A, which #imports library B and uses some functions / variables in that, will that work correctly? Can the map script also use variables and functions in library B?
Here's how it breaks down. If library A uses code from Library B, Library A will have to import B to complile. However, if you have a map that needs to use A and B's functions, you will need to Import both library A and B into your map script. Import will import its-self, but not anything it has imported.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: Importing a library problem

Post by Macil »

Ok, that makes sense - libraries #imported can't pull in other libraries.

What about libraries loaded by LOADACS? Can they #import another library and work fine?
Locked

Return to “Editing (Archive)”