Unable to resolve symbols when importing my development haxelib - haxe

In the haxelib project folder, I am running haxelib dev cc_gfx ..
In the importing project folder, haxe build.hxml.
I get the error src/shader/Shader.hx:3: characters 7-19 : Type not found : gfx.Vector2f.
build.hxml:
-cp src
-lib cc_gfx
-main shader.Shader
-lua out/main.lua
haxelib.json:
{
"name": "cc_gfx",
"license": "MIT",
"description": "Bindings to the gfx library for ComputerCraft.",
"version": "0.0.1",
"classPath": "src",
"releasenote": "Initial release.",
"contributors": ["James King"]
}
Shader.hx:
package shader;
import gfx.Vector2f;
class Shader {
static public function main() {
var v = new Vector2f(1, 1);
}
}
Vector.hx:
package gfx;
public class Vector2f {
var x : Float;
var y : Float;
Vector2f(x : Float, y : Float) {
this.x = x;
this.y = y;
}
}

This is actually not related to the files being in a Haxelib.
src/shader/Shader.hx:3: characters 8-20 : Type not found : gfx.Vector2f
import gfx.Vector2f; is trying to import a module that doesn't exist, it's actually named Vector (since the file name is Vector.hx). The module name doesn't have to match the class name, but then the import needs to be adjusted to import gfx.Vector;. Or just change the file name to Vector2f.hx.
After that is fixed, the compiler will report two more errors, since the code in Vector has some syntax issues:
src/gfx/Vector.hx:3: characters 1-7 : Unexpected public
Types in Haxe are public by default, so there's no public modifier allowed. After that:
src/gfx/Vector.hx:6: characters 5-13 : Unexpected Vector2f
That's not how you declare a constructor in Haxe. Vector2f(x:Float, y:Float) should be replaced with public function new(x:Float, y:Float).

Related

How can I rectify static scope error when referencing a static variable in my groovy script?

I have a script which exports excel worksheets to csv, and I am attempting to escape commas, quotes and the like. I have created a static method that encodes the value of the cell being accessed. This method references a static variable which stores a Pattern.compile() value.
I have tried using def rxquote within the method but this gives me a different error stating that using static modifier before declaring my rxquote variable is illegal. Code is below followed by error message.
#!/usr/bin/env groovy
#Grab(group = 'org.apache.poi', module = 'poi', version = '4.1.0')
#Grab(group = 'org.apache.poi', module = 'poi-ooxml', version = '4.1.0')
import java.util.regex.*
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.apache.poi.ss.usermodel.*
static Pattern rxquote = Pattern.compile("\"")
static private String encodeValue(String value) {
boolean needQuotes = false;
if ( value.indexOf(',') != -1 || value.indexOf('"') != -1 ||
value.indexOf('\n') != -1 || value.indexOf('\r') != -1 ){
needQuotes = true;
}
Matcher m = rxquote.matcher(value)
if ( m.find() ) {
needQuotes = true
value = m.replaceAll("\"\"")
}
if ( needQuotes ) {
return "\"" + value + "\""
}
else return value;
}
//for(){
// ... export csv code (which works on its own)
//}
Error message on compile:
Apparent variable 'rxquote' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'rxquote' but left out brackets in a place not allowed by the grammar.
# line 27, column 17.
Matcher m = rxquote.matcher(value);
^
I've tried researching the issue and have found several similar questions here, but none of the solutions appear to apply to this situation as far as I can tell. I expected a static declaration of the variable to avoid this problem, but it seems there's something I'm missing.
you can't declare static variable in groovy script.
it's allowed only in groovy/java class.
error does not correspond to situation.
should be : Modifier 'static' not allowed here.
as workaround for static variables you can use some class:
class Const{
static String bar = 'test'
}
static private String foo() {
return Const.bar
}
foo()

Possible to make custom class named "Map", and still reference the Haxe "Map" class?

Is it possible to make a class called Map:
// src/test/Map.hx
package test;
class Map {
public function new ( a : Int, b : Int : c : Int ) {
trace( a + b + c );
}
}
And then somehow access both this new Map class AND the original Haxe Map construct in Foo.hx?
// src/test/Foo.hx
package test;
class Foo {
var map1 : test.Map = new test.Map( 1, 2, 3 );
var map2 : Map<Int, String> = [ 0 => "Hello" ];
}
This doesn't work, because the map2 type is automatically resolving to test.Map (not the Haxe one) because Foo.hx is part of the test package which contains the new Map class.
If the Haxe Map construct was part of a package, this would be easy (could just say package_name.Map). However, it has no package. So is there no way to access both?
With Haxe 4 you will be able to use haxe.ds.Map.
Meanwhile, you should be able to access haxe's Map with std.Map.

java 9 : confusing rules about Resources and modules

In module com.thing.withprops I have this code in com.thing.withprops.UseProps.java:
URL url =UseProps.class.getResource("config/values.properties") ;
module-info is
module com.thing.withprops { exports com.thing.withprops;}
now there is another module with name com.thing.withprops.config where lies a values.properties file in directory com/thing/withprops/config/
the module-info is just this:
module com.thing.withprops.config{}
well when everything is jarred and executed all is working perfectly: the resource is found! I am confused because it seems that the doc says it shouldn't be found since it is in another module which is not exported or opened.
So what is wrong? the way I understand doc (I am not a native speaker) or my code?
thanks for any hint
in fact there are two problems there : one is about handling resources and the other is about java -jar behavior
here is a suggestion on how to handle resources in a modular project:
public interface ResourceLoader {
public static Optional<URL> resourceSearch(Class clazz, String name) {
String fullPath = name ;
if(! name.startsWith("/")) {
String packageName = clazz.getPackageName();
fullPath = '/'+packageName.replace('.','/')+ '/' + name;
}
ServiceLoader<ResourceLoader> loader = ServiceLoader.load(ResourceLoader.class);
for(ResourceLoader resourceLoader: loader) {
Optional<URL> anUrl =resourceLoader.getResource(fullPath);
if(anUrl.isPresent()) {
return anUrl ;
}
}
return Optional.empty() ;
}
public static Optional<InputStream> resourceSearchAsStream(Class clazz, String name) throws IOException {
Optional<URL> anURL = resourceSearch(clazz, name) ;
if(anURL.isPresent()){
InputStream is = anURL.get().openStream() ;
return Optional.of(is) ;
}
return Optional.empty() ;
}
public default Optional<URL> getResource(String fullPath) {
Class localClass = this.getClass() ;
URL res = localClass.getResource(fullPath) ;
return Optional.ofNullable(res) ;
}
}
then one can deploy another module with resources with module-info like :
open module com.thing.withprops.config {
requires com.thing.withprops;
provides com.thing.withprops.utils.ResourceLoader with com.thing.withprops.spi.ResourceLoaderImpl ;
}
any other suggestion?
(still trying to find a way to have something looking like a "clickable" jar ...but could be hopeless)

g++ error: expected ; before "it"

I'm porting C++ app from Solaris to Linux and I'm stuck with the following error. The code is:
template <class MapSuperClass> class FWPointerMap : public MapSuperClass
{
public:
FWPointerMap()
{
_wipe = false;
}
FWPointerMap(const MapSuperClass* mMap)
{
MapSuperClass::const_iterator it = mMap->begin(); // line 50
while(it != mMap->end())
{
insert(MapSuperClass::value_type((*it).first, (*it).second));
it++;
}
_wipe = false;
}
And I get the following error:
../../framework/fwcore/hdr/FWPointerMap: In constructor FWPointerMap<MapSuperClass>::FWPointerMap(const MapSuperClass*):
../../framework/fwcore/hdr/FWPointerMap:50: error: expected ; before it
../../framework/fwcore/hdr/FWPointerMap:52: error: it was not declared in this scope
I think you just need to add 'typename' to tell the compiler that MapSuperClass::const_iterator is a type:
typename MapSuperClass::const_iterator it = mMap->begin(); // line 50
Because MaySuperClass is a class template parameter, the assumption is that the const_iterator member is a field. Using typename informs the compiler that it is in fact a type.
More information: http://en.wikipedia.org/wiki/Typename#A_method_for_indicating_that_a_dependent_name_is_a_type

haxe abstract code not working for neko

The following code compiles to Javascript and runs OK, http://try.haxe.org/#8C940
abstract Comparable(Dynamic) from Float from String {
#:op(a<b) static function lt(a, b):Bool;
}
class Test {
public static function min<T:Comparable>(t:T, t2:T):T {
return (t:Comparable) < (t2:Comparable) ? t : t2;
}
static function main() {
var a = min(1.1,2.2); //ok
$type(a); //Float
trace(a); //1.1
var b = min(1,2); //ok
$type(b); //Int
trace(b); //1
var c = min("a","b"); //ok
$type(c); //String
trace(c); //a
//following will produce compilation error, correctly
//min(0, "a");
}
}
But when compiled for neko, it gives the following error:
Main.hx:7: characters 12-13 : Unexpected :
Main.hx:7: characters 12-13 : Unexpected :
Uncaught exception - load.c(181) : Module not found : main.n
The error in question is line:
return (t:Comparable) < (t2:Comparable) ? t : t2;
Any ideas why the language featuer works in one target but not the other? And how can I fix the issue for neko?
Thanks.
i guess you have a compiler version conflict, can you try the latest development builds:
http://hxbuilds.s3-website-us-east-1.amazonaws.com/builds/haxe/
(you can find the link here: http://haxe.org/manual/haxe3#git-builds -- edit: this page does not exist any more, but the build page is available via http://build.haxe.org)

Resources