Binding for AngelScript or Squirrel

Just starting out? Need help? Post your questions and find answers here.
User avatar
X0r
Enthusiast
Enthusiast
Posts: 138
Joined: Tue May 01, 2007 3:49 am
Location: Germany

Binding for AngelScript or Squirrel

Post by X0r »

Hey guys,

is there anyone who has created a wrapper for both AngelScript and/or Squirrel to be used in PureBasic?
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Binding for AngelScript or Squirrel

Post by infratec »

Hm...

4 years ago I gave some hints about squirrel:

https://www.purebasic.fr/english/viewto ... 33#p486633
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Binding for AngelScript or Squirrel

Post by infratec »

dofile works, but compile still fails.

Code: Select all

ImportC "squirrel.lib"
  sq_open.i(stacksize.l)
  sq_pop(*vm, nelementstoppop.l)
  sq_close(*vm)
  sq_pushroottable(*vm)
  sq_pushstring(*vm, f.p-UTF8, len.l)
  sq_get(*vm, idx.l)
  sq_pushinteger(*vm, ni.l)
  sq_pushfloat(*vm, nf.f)
  sq_call.i(*vm, param.l, retval.l, raiseerror.l)
  sq_compile.i(*vm, *ReadFunc, parameter.i, sourcename.p-UTF8, raiseerror.l)
  sq_setcompilererrorhandler(*vm, *ErrorFunc)
  sq_setprintfunc(*vm, *PrintFunc, *ErrorFunc)
EndImport


ImportC "sqstdlib.lib"
  sqstd_dofile(*vm, filename.p-UTF8, retval.l, printerror.l)
  sqstd_loadfile(*vm, filename.p-UTF8, printerror.l)
EndImport



ProcedureC ErrorFunc(*vm, *desc, *source, line.i, column.i)
  Debug PeekS(*desc, -1, #PB_UTF8)
  Debug PeekS(*source, -1, #PB_UTF8) + " line: " + Str(line) + " col: " + Str(column)
EndProcedure

ProcedureC PrintFunc(*vm, *s, *a)
  Debug PeekS(*s, -1, #PB_UTF8)
  Debug PeekS(*a, -1, #PB_UTF8)
EndProcedure


ProcedureC.a GetCharFileFunc(hFile.i)
  
  Protected Byte.a
  
  ReadData(hFile, @Byte, 1)
  ;Debug RSet(Hex(Byte), 2, "0") + " " + Chr(Byte)
  
  ProcedureReturn Byte
  
EndProcedure


Define hFile.i

*vm = sq_open(10240)
If *vm
  
  sq_setcompilererrorhandler(*vm, @ErrorFunc())
  sq_setprintfunc(*vm, @PrintFunc(), #Null)
  
  Debug sq_pushroottable(*vm)
  
  hFile = ReadFile(#PB_Any, "HelloWorld.nut")
  If hFile
    
    Debug sq_compile(*vm, @GetCharFileFunc(), hFile, "HelloWorld.nut", #True)
    
    CloseFile(hFile)
    
    ;   
    Debug sqstd_dofile(*vm, "HelloWorld.nut", #False, #True)
    ;Debug sqstd_dofile(*vm, "compileError.nut", #False, #True)
    ;   
    ;   Debug sq_pushstring(*vm, "foo", -1)
    ;   Debug sq_get(*vm, -2)
    ;   Debug sq_pushinteger(*vm, 1)
    ;   Debug sq_pushfloat(*vm, 2.0)
    ;   Debug sq_pushstring(*vm, "three", -1)
    ;   Debug sq_call(*vm, 4, #False, #True)
    Debug sq_pop(*vm, 1)
    
  EndIf
  
  
  sq_close(*vm)
  
EndIf

User avatar
X0r
Enthusiast
Enthusiast
Posts: 138
Joined: Tue May 01, 2007 3:49 am
Location: Germany

Re: Binding for AngelScript or Squirrel

Post by X0r »

Nice to see that you have been working on this.

Are you trying to use the static library? Because I had similar problems when I tried to link against the static library of AngelScript. I was able to trace it back to the standard C/C++ string library and had to apply changes to the AngelScript source code in order to make it work. However, I was not happy with that solution as would like to use it as it is.
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Binding for AngelScript or Squirrel

Post by chi »

infratec wrote:dofile works, but compile still fails.
I was able to run your code with with the dynamic lib/dll of Squirrel...

Output from the debugger:

Code: Select all

4750208
0
%s
Hello World!
1
863838721
With the static lib, though, I ran into some problems:

Code: Select all

POLINK: warning: Unrecognized option '/FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0'; ignored.
POLINK: warning: Unrecognized option '/FAILIFMISMATCH:_MSC_VER=1900'; ignored.
POLINK: warning: Unrecognized option '/FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=0'; ignored.
POLINK: warning: Unrecognized option '/FAILIFMISMATCH:RuntimeLibrary=MD_DynamicRelease'; ignored.
POLINK: warning: Unrecognized option '/FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0'; ignored.
POLINK: warning: Unrecognized option '/FAILIFMISMATCH:_MSC_VER=1900'; ignored.
POLINK: warning: Unrecognized option '/FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=0'; ignored.
...
POLINK: fatal error: 8 unresolved external(s).
Et cetera is my worst enemy
Post Reply